pull/2481/head
FengbinShi 2 years ago
parent cca30c9c80
commit 24a2850265
  1. 8
      health/checker.go
  2. 9
      health/health_test.go

@ -2,6 +2,7 @@ package health
import ( import (
"context" "context"
"fmt"
"sync" "sync"
"time" "time"
) )
@ -53,10 +54,13 @@ func (c *checkerHandler) getName() string {
return c.Name return c.Name
} }
func (c *checkerHandler) check(ctx context.Context) bool { func (c *checkerHandler) check(ctx context.Context) (r bool) {
defer func() { defer func() {
if err := recover(); err != nil { if err := recover(); err != nil {
r = true
c.Lock()
c.CheckerStatus.Err = fmt.Errorf("%v", err)
c.Unlock()
} }
}() }()

@ -2,14 +2,14 @@ package health
import ( import (
"fmt" "fmt"
"golang.org/x/net/context"
"math/rand" "math/rand"
"testing" "testing"
"time" "time"
"golang.org/x/net/context"
) )
type A struct { type A struct{}
}
func (A) Check(ctx context.Context) (interface{}, error) { func (A) Check(ctx context.Context) (interface{}, error) {
fmt.Println("check A") fmt.Println("check A")
@ -19,8 +19,7 @@ func (A) Check(ctx context.Context) (interface{}, error) {
return "正常A", nil return "正常A", nil
} }
type B struct { type B struct{}
}
func (B) Check(ctx context.Context) (interface{}, error) { func (B) Check(ctx context.Context) (interface{}, error) {
fmt.Println("check B") fmt.Println("check B")

Loading…
Cancel
Save