-
Notifications
You must be signed in to change notification settings - Fork 0
/
health_checker.go
50 lines (42 loc) · 954 Bytes
/
health_checker.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
package activemq
import (
"context"
"github.com/go-stomp/stomp"
)
type HealthChecker struct {
name string
addr string
}
func NewHealthChecker(addr string, options ...string) *HealthChecker {
var name string
if len(options) >= 2 && len(options[1]) >= 0 {
name = options[1]
} else {
name = "amq"
}
return &HealthChecker{name, addr}
}
func (s *HealthChecker) Name() string {
return s.name
}
func (s *HealthChecker) Check(ctx context.Context) (map[string]interface{}, error) {
var conn *stomp.Conn
res := make(map[string]interface{})
var err error
conn, err = stomp.Dial("tcp", s.addr)
if err != nil {
return res, err
}
res["version"] = conn.Version()
return res, err
}
func (s *HealthChecker) Build(ctx context.Context, data map[string]interface{}, err error) map[string]interface{} {
if err == nil {
return data
}
if data == nil {
data = make(map[string]interface{}, 0)
}
data["error"] = err.Error()
return data
}