-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdiscovery.go
43 lines (39 loc) · 1.11 KB
/
discovery.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
package pluto
import (
"fmt"
"github.com/aukbit/pluto/v6/common"
"github.com/aukbit/pluto/v6/discovery"
)
// register Pluto Service within the service discovery system
func (s *Service) register() error {
if _, ok := s.cfg.Discovery.(discovery.Discovery); ok {
// define service
dse := discovery.Service{
Name: s.cfg.Name,
Tags: []string{s.cfg.ID},
}
// define check
dck := discovery.Check{
Name: fmt.Sprintf("Service '%s' check", s.cfg.Name),
Notes: fmt.Sprintf("Ensure the Pluto service %s is running", s.cfg.ID),
DeregisterCriticalServiceAfter: "10m",
HTTP: fmt.Sprintf("http://%s:9090/_health/pluto/%s", common.IPaddress(), s.cfg.Name),
Interval: "10s",
Timeout: "1s",
ServiceID: s.cfg.Name,
}
if err := s.cfg.Discovery.Register(discovery.ServicesCfg(dse), discovery.ChecksCfg(dck)); err != nil {
return err
}
}
return nil
}
// unregister Server from the service discovery system
func (s *Service) unregister() error {
if _, ok := s.cfg.Discovery.(discovery.Discovery); ok {
if err := s.cfg.Discovery.Unregister(); err != nil {
return err
}
}
return nil
}