-
Notifications
You must be signed in to change notification settings - Fork 2
/
health.go
64 lines (50 loc) · 1.53 KB
/
health.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package health
import (
"context"
"github.com/americanas-go/health"
"github.com/americanas-go/log"
"github.com/gocql/gocql"
)
// Register registers a new health plugin on gocql session.
func Register(ctx context.Context, session *gocql.Session) error {
o, err := NewOptions()
if err != nil {
return nil
}
h := NewHealthWithOptions(o)
return h.Register(ctx, session)
}
// Health represents health plugin from gocql.
type Health struct {
options *Options
}
// NewHealthWithOptions returns a new health checker with options.
func NewHealthWithOptions(options *Options) *Health {
return &Health{options: options}
}
// NewHealthWithOptions returns a new health checker with options from config path.
func NewHealthWithConfigPath(path string) (*Health, error) {
o, err := NewOptionsWithPath(path)
if err != nil {
return nil, err
}
return NewHealthWithOptions(o), nil
}
// NewHealth returns a new health checker with default options
func NewHealth() *Health {
o, err := NewOptions()
if err != nil {
log.Fatalf(err.Error())
}
return NewHealthWithOptions(o)
}
// Register registers this health checker plugin on gocql session.
func (i *Health) Register(ctx context.Context, session *gocql.Session) error {
logger := log.FromContext(ctx).WithTypeOf(*i)
logger.Trace("integrating gocql in health")
checker := NewChecker(session)
hc := health.NewHealthChecker(i.options.Name, i.options.Description, checker, i.options.Required, i.options.Enabled)
health.Add(hc)
logger.Debug("gocql successfully integrated in health")
return nil
}