# README
xpanic
panic
辅助函数
error
不为nil
时,panic
true
时,panic
try cache panic
例子
Do(func() {
fmt.Println("Doing something...")
panic("Something wrong happened!")
}, func(p *Panic) {
fmt.Println("Caught a panic:", p.Reason)
})
AutoRecover("something", func(){
// do something
// if panic, auto execute this function continue.
})
Try(func() {
WhenErrorAsFmtFirst(err, "%w, %d", 1)
}).Catch(func(err E) {
fmt.Println(err)
})
Output:
error, 1
# Functions
AutoRecover 执行 f ,当 f 发生panic,启动新的协程重复 AutoRecover.
go:generate optiongen --option_with_struct_name=true --option_return_previous=false.
Catch recovers from panic.
Do executes f.
InstallAutoRecoverOptionsWatchDog the installed func will called when NewAutoRecoverOptions called.
NewAutoRecoverOptions new AutoRecoverOptions.
No description provided by the author
No description provided by the author
WhenError err 不为 nil 则 panic.
WhenErrorAsFmtFirst err 不为 nil 则 wrap 并 panic,将 err 作为第一个 fmt 的参数 xpanic.WhenErrorAsFmtFirst(err, "got error: %w while reading file: %s", filePath).
WhenFalse 当 condition 为 false 时 panic.
WhenHereNotNil 提供运行到此处返回的error应为nil的语义,避免在框架层吃掉error 功能逻辑等同WhenError,但是语义上调用者确定这里不会返回错误.
WhenTrue 当 condition 为 true 时 panic.
WithAutoRecoverOptionDelayTime 每次panic后重启delay的时间 Note: 这里应该可以直接对接到retry package,复用重试逻辑.
WithAutoRecoverOptionOnRecover 如果指定了该函数,recover panic的时候,会执行该函数,默认输出error日志.
# Structs
AutoRecoverOptions should use NewAutoRecoverOptions to initialize it.
Panic is a snapshot of a panic, containing both the panic's reason and the system stack.
# Interfaces
AutoRecoverOptionsInterface visitor + ApplyOption interface for AutoRecoverOptions.
AutoRecoverOptionsVisitor visitor interface for AutoRecoverOptions.
No description provided by the author