-
Notifications
You must be signed in to change notification settings - Fork 4
/
registry.go
52 lines (41 loc) · 1.01 KB
/
registry.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
package static
import (
"github.com/moderntv/cadre/registry"
)
type staticRegistry map[string][]registry.Instance
func NewRegistry(cfg map[string][]string) (registry.Registry, error) {
r := staticRegistry{}
for service, instances := range cfg {
r[service] = []registry.Instance{}
for _, addr := range instances {
r[service] = append(r[service], &instance{
serviceName: service,
addr: addr,
})
}
}
return &r, nil
}
func (this *staticRegistry) Register(serviceInstance registry.Instance) error {
return nil
}
func (this *staticRegistry) Deregister(serviceInstance registry.Instance) error {
return nil
}
func (this *staticRegistry) Instances(service string) []registry.Instance {
if this == nil {
return []registry.Instance{}
}
is, ok := (*this)[service]
if !ok {
return []registry.Instance{}
}
return is
}
func (this *staticRegistry) Watch(service string) (<-chan registry.RegistryChange, func()) {
c := make(chan registry.RegistryChange)
f := func() {
close(c)
}
return c, f
}