/
discovery.go
74 lines (59 loc) · 1.18 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
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
package discovery
import "time"
// NodeState define the node state type
type NodeState int32
const (
// NodeUp node starting up
NodeUp NodeState = 0
// NodeDown node shutdown
NodeDown NodeState = 1
// NodeKeepalive node keepalive
NodeKeepalive NodeState = 2
DefaultPublishPrefix = "node.publish"
DefaultDiscoveryPrefix = "node.discovery"
DefaultLivecycle = 2 * time.Second
DefaultExpire = 5
)
type Action string
const (
Save Action = "save"
Update Action = "update"
Delete Action = "delete"
Get Action = "get"
)
type Protocol string
const (
GRPC Protocol = "grpc"
NGRPC Protocol = "nats-grpc"
JSONRPC Protocol = "json-rpc"
)
type RPC struct {
Protocol Protocol
Addr string
Params map[string]string
}
// Node represents a node info
type Node struct {
DC string
Service string
NID string
RPC RPC
ExtraInfo map[string]interface{}
}
// ID return the node id with scheme prefix
func (n *Node) ID() string {
return n.DC + "." + n.NID
}
type Request struct {
Action Action
Node Node
Service string
Params map[string]interface{}
}
type Response struct {
Success bool
Reason string
}
type GetResponse struct {
Nodes []Node
}