initial commit
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
package recovery
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"sync"
|
||||
)
|
||||
|
||||
func logf(format string, args ...interface{}) {
|
||||
log.Printf("[recovery] "+format, args...)
|
||||
}
|
||||
|
||||
func safeRecover(where string) {
|
||||
if r := recover(); r != nil {
|
||||
logf("panic recovered in %s: %v", where, r)
|
||||
}
|
||||
}
|
||||
|
||||
func recoverErrors(where string, errs *[]string, mu *sync.Mutex) {
|
||||
if r := recover(); r != nil {
|
||||
logf("panic recovered in %s: %v", where, r)
|
||||
mu.Lock()
|
||||
*errs = append(*errs, fmt.Sprintf("%s: %v", where, r))
|
||||
mu.Unlock()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user