diff --git a/health/checker.go b/health/checker.go index ab03d3fa9..7b5300d9a 100644 --- a/health/checker.go +++ b/health/checker.go @@ -2,6 +2,7 @@ package health import ( "context" + "fmt" "sync" "time" ) @@ -53,10 +54,13 @@ func (c *checkerHandler) getName() string { return c.Name } -func (c *checkerHandler) check(ctx context.Context) bool { +func (c *checkerHandler) check(ctx context.Context) (r bool) { defer func() { if err := recover(); err != nil { - + r = true + c.Lock() + c.CheckerStatus.Err = fmt.Errorf("%v", err) + c.Unlock() } }() @@ -92,7 +96,7 @@ func (c *checkerHandler) run(ctx context.Context) { default: } if c.check(ctx) { - //notify + // notify if c.Notifier != nil { c.Notifier.notify(c.Name) } diff --git a/health/health_test.go b/health/health_test.go index 0e5d69f27..4aec797b2 100644 --- a/health/health_test.go +++ b/health/health_test.go @@ -2,14 +2,14 @@ package health import ( "fmt" - "golang.org/x/net/context" "math/rand" "testing" "time" + + "golang.org/x/net/context" ) -type A struct { -} +type A struct{} func (A) Check(ctx context.Context) (interface{}, error) { fmt.Println("check A") @@ -19,8 +19,7 @@ func (A) Check(ctx context.Context) (interface{}, error) { return "正常A", nil } -type B struct { -} +type B struct{} func (B) Check(ctx context.Context) (interface{}, error) { fmt.Println("check B")