-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdiscovery.go
45 lines (36 loc) · 948 Bytes
/
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
44
45
package sprintsd
import "context"
type Discovery struct {
store Store
}
func NewDiscovery(store Store) *Discovery {
return &Discovery{
store: store,
}
}
func (d *Discovery) Enroll(ctx context.Context, reg *Registration) error {
return d.store.Save(ctx, reg)
}
func (d *Discovery) Locate(ctx context.Context, name string) (
r *Registration, err error,
) {
r, err = d.store.Query(ctx, name)
if err != nil {
return nil, err
}
return r, nil
}
func (d *Discovery) Forget(ctx context.Context, name string) error {
return d.store.Delete(ctx, name)
}
type Registration struct {
ID string `json:"id" firestore:"id"`
Name string `json:"name" firestore:"name"`
Address string `json:"address" firestore:"address"`
Port int `json:"port" firestore:"port"`
}
type Store interface {
Save(context.Context, *Registration) error
Query(context.Context, string) (*Registration, error)
Delete(context.Context, string) error
}