-
Notifications
You must be signed in to change notification settings - Fork 0
/
service.go
68 lines (62 loc) · 1.42 KB
/
service.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
package registry
import "time"
//服务
type Service struct {
Name string `json:"name"`
Nodes []*Node `json:"nodes"`
}
//节点
type Node struct {
Id string `json:"id"` //uuid
Name string `json:"name"` //服务名称
Address string `json:"address"` //服务IP
Port int `json:"port"` //端口
//下面是java使用的字段
Payload *Payload `json:"payload"`
RegstrationTimeUTC int64 `json:"registrationTimeUTC"`
ServiceType string `json:"serviceType"`
UriSpec *UriSpec `json:"uriSpec"`
}
/*********** 以下 java 使用 **************/
type Payload struct {
Class string `json:"@class"`
}
type UriSpec struct {
Parts []*UriSpecParts `json:"parts"`
}
type UriSpecParts struct {
Value string `json:"value"`
Variable bool `json:"variable"`
}
//添加java支持
func addJava(node *Node) {
node.Payload = &Payload{
Class: "org.springframework.cloud.zookeeper.discovery.ZookeeperInstance",
}
node.RegstrationTimeUTC = time.Now().UnixNano() / 1e6
node.ServiceType = "DYNAMIC"
node.UriSpec = &UriSpec{
Parts: []*UriSpecParts{
&UriSpecParts{
Value: "scheme",
Variable: true,
},
&UriSpecParts{
Value: "://",
Variable: false,
},
&UriSpecParts{
Value: "address",
Variable: true,
},
&UriSpecParts{
Value: ":",
Variable: true,
},
&UriSpecParts{
Value: "port",
Variable: true,
},
},
}
}