forked from hashicorp/consul
-
Notifications
You must be signed in to change notification settings - Fork 0
/
structs.go
56 lines (50 loc) · 1.13 KB
/
structs.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
package agent
import (
"github.com/hashicorp/consul/consul/structs"
)
// ServiceDefinition is used to JSON decode the Service definitions
type ServiceDefinition struct {
ID string
Name string
Tags []string
Port int
Check CheckType
}
func (s *ServiceDefinition) NodeService() *structs.NodeService {
ns := &structs.NodeService{
ID: s.ID,
Service: s.Name,
Tags: s.Tags,
Port: s.Port,
}
if ns.ID == "" && ns.Service != "" {
ns.ID = ns.Service
}
return ns
}
func (s *ServiceDefinition) CheckType() *CheckType {
if s.Check.Script == "" && s.Check.Interval == 0 && s.Check.TTL == 0 {
return nil
}
return &s.Check
}
// ChecKDefinition is used to JSON decode the Check definitions
type CheckDefinition struct {
ID string
Name string
Notes string
CheckType `mapstructure:",squash"`
}
func (c *CheckDefinition) HealthCheck(node string) *structs.HealthCheck {
health := &structs.HealthCheck{
Node: node,
CheckID: c.ID,
Name: c.Name,
Status: structs.HealthUnknown,
Notes: c.Notes,
}
if health.CheckID == "" && health.Name != "" {
health.CheckID = health.Name
}
return health
}