-
Notifications
You must be signed in to change notification settings - Fork 4
/
types.go
101 lines (91 loc) · 1.91 KB
/
types.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package registry
import "sync"
const (
SERVICE_STATUS_UNDEFINED int8 = iota + 1
SERVICE_STATUS_PASSING
SERVICE_STATUS_WARNING
SERVICE_STATUS_CRITICAL
)
// Registry functionality definition
type Registry interface {
KV() KV
Bind(i sync.Locker) error
Discovery() Discovery
Refresh()
}
// KV is key value storage functionality definition
type KV interface {
Get(string) (string, error)
Set(key, value string) error
List(prefix string) (map[string]string, error)
Delete(string) error
}
// Descovery service functionality definition
type Discovery interface {
Lookup(*Filter) ([]Service, error)
Register(ServiceOptions) error
Deregister(string) error
}
// Service config definition
type Service struct {
ID string
Name string
Datacenter string
Address string
Port int
Tags []string
Status int8
}
func (s *Service) test(filter *Filter) bool {
if filter == nil {
return true
}
if len(filter.ID) != 0 && filter.ID != s.ID {
return false
}
if filter.Status != 0 && filter.Status != s.Status {
return false
}
if len(filter.Datacenter) != 0 && filter.Datacenter != s.Datacenter {
return false
}
if len(filter.Service) != 0 && filter.Service != s.Name {
return false
}
if len(filter.Tags) != 0 {
for _, ft := range filter.Tags {
for _, st := range s.Tags {
if ft == st {
return true
}
}
}
return false
}
return true
}
// Filter search descovery definition
type Filter struct {
ID string
Status int8
Tags []string
Service string
Datacenter string
}
// ServiceOptions defines proxy sevice object
type ServiceOptions struct {
ID string
Name string
Address string
Tags []string
Check CheckOptions
}
// CheckOptions defines sevice healthcheck
type CheckOptions struct {
Interval string
Timeout string
HTTP string
TCP string
TTL string
DeregisterAfter string
}