-
Notifications
You must be signed in to change notification settings - Fork 0
/
watch.go
328 lines (286 loc) · 13 KB
/
watch.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
package consultant
import (
"github.com/hashicorp/consul/api/watch"
)
// WatchKey wraps the creation of a "key" plan
func WatchKey(key string, stale bool, token, datacenter string) (*watch.Plan, error) {
return watch.Parse(map[string]interface{}{
"type": "key",
"key": key,
"stale": stale,
"token": token,
"datacenter": datacenter,
})
}
// WatchKeyHandler wraps the creation of a "key" plan, additionally assigning an index handler func
func WatchKeyHandler(key string, stale bool, token, datacenter string, handler watch.HandlerFunc) (wp *watch.Plan, err error) {
if wp, err = WatchKey(key, stale, token, datacenter); wp != nil {
wp.Handler = handler
}
return
}
// WatchKeyHybridHandler wraps the creation of a "key" plan, additionally assigning hybrid (hash) handler func
func WatchKeyHybridHandler(key string, stale bool, token, datacenter string, hybridHandler watch.HybridHandlerFunc) (wp *watch.Plan, err error) {
if wp, err = WatchKey(key, stale, token, datacenter); wp != nil {
wp.HybridHandler = hybridHandler
}
return
}
// WatchKeyPrefix wraps the creation of a "keyprefix" plan
func WatchKeyPrefix(prefix string, stale bool, token, datacenter string) (*watch.Plan, error) {
return watch.Parse(map[string]interface{}{
"type": "keyprefix",
"prefix": prefix,
"stale": stale,
"token": token,
"datacenter": datacenter,
})
}
// WatchKeyPrefixHandler wraps the creation of a "keyprefix" plan, additionally assigning an index handler func
func WatchKeyPrefixHandler(prefix string, stale bool, token, datacenter string, handler watch.HandlerFunc) (wp *watch.Plan, err error) {
if wp, err = WatchKeyPrefix(prefix, stale, token, datacenter); wp != nil {
wp.Handler = handler
}
return
}
// WatchKeyPrefixHybridHandler wraps the creation of a "keyprefix" plan, additionally assigning a hash handler func
func WatchKeyPrefixHybridHandler(prefix string, stale bool, token, datacenter string, handler watch.HybridHandlerFunc) (wp *watch.Plan, err error) {
if wp, err = WatchKeyPrefix(prefix, stale, token, datacenter); wp != nil {
wp.HybridHandler = handler
}
return
}
// WatchServices wraps the creation of a "services" plan
func WatchServices(stale bool, token, datacenter string) (*watch.Plan, error) {
return watch.Parse(map[string]interface{}{
"type": "services",
"stale": stale,
"token": token,
"datacenter": datacenter,
})
}
// WatchServicesHandler wraps the creation of a "services" plan, additionally assigning an index handler
func WatchServicesHandler(stale bool, token, datacenter string, handler watch.HandlerFunc) (wp *watch.Plan, err error) {
if wp, err = WatchServices(stale, token, datacenter); wp != nil {
wp.Handler = handler
}
return
}
// WatchServicesHybridHandler wraps the creation of a "services" plan, additionally assigning a hash handler
func WatchServicesHybridHandler(stale bool, token, datacenter string, handler watch.HybridHandlerFunc) (wp *watch.Plan, err error) {
if wp, err = WatchServices(stale, token, datacenter); wp != nil {
wp.HybridHandler = handler
}
return
}
// WatchNodes wraps the creation of a "nodes" plan
func WatchNodes(stale bool, token, datacenter string) (*watch.Plan, error) {
return watch.Parse(map[string]interface{}{
"type": "nodes",
"stale": stale,
"token": token,
"datacenter": datacenter,
})
}
// WatchNodesHandler wraps the creation of a "nodes" plan, additionally assigning an index handler
func WatchNodesHandler(stale bool, token, datacenter string, handler watch.HandlerFunc) (wp *watch.Plan, err error) {
if wp, err = WatchNodes(stale, token, datacenter); wp != nil {
wp.Handler = handler
}
return
}
// WatchNodesHybridHandler wraps the creation of a "nodes" plan, additionally assigning a hash handler
func WatchNodesHybridHandler(stale bool, token, datacenter string, handler watch.HybridHandlerFunc) (wp *watch.Plan, err error) {
if wp, err = WatchNodes(stale, token, datacenter); wp != nil {
wp.HybridHandler = handler
}
return
}
func WatchServiceMultipleTags(service string, tags []string, passingOnly, stale bool, token, datacenter string) (*watch.Plan, error) {
return watch.Parse(map[string]interface{}{
"type": "service",
"service": service,
"tag": tags,
"passingonly": passingOnly,
"stale": stale,
"token": token,
"datacenter": datacenter,
})
}
// WatchService wraps the creation of a "service" plan
func WatchService(service, tag string, passingOnly, stale bool, token, datacenter string) (*watch.Plan, error) {
var tags []string
if tag != "" {
tags = []string{tag}
}
return WatchServiceMultipleTags(service, tags, passingOnly, stale, token, datacenter)
}
// WatchServiceHandler wraps the creation of a "service" plan, additionally setting an index handler
func WatchServiceHandler(service, tag string, passingOnly, stale bool, token, datacenter string, handler watch.HandlerFunc) (wp *watch.Plan, err error) {
if wp, err = WatchService(service, tag, passingOnly, stale, token, datacenter); wp != nil {
wp.Handler = handler
}
return
}
// WatchServiceHybridHandler wraps the creation of a "service" plan, additionally setting a hash handler
func WatchServiceHybridHandler(service, tag string, passingOnly, stale bool, token, datacenter string, handler watch.HybridHandlerFunc) (wp *watch.Plan, err error) {
if wp, err = WatchService(service, tag, passingOnly, stale, token, datacenter); wp != nil {
wp.HybridHandler = handler
}
return
}
// WatchChecks wraps the creation of a "checks" plan
func WatchChecks(service, state string, stale bool, token, datacenter string) (*watch.Plan, error) {
return watch.Parse(map[string]interface{}{
"type": "checks",
"service": service,
"state": state,
"stale": stale,
"token": token,
"datacenter": datacenter,
})
}
// WatchChecksHandler wraps the creation of a "checks" plan, additionally setting an index handler
func WatchChecksHandler(service, state string, stale bool, token, datacenter string, handler watch.HandlerFunc) (wp *watch.Plan, err error) {
if wp, err = WatchChecks(service, state, stale, token, datacenter); wp != nil {
wp.Handler = handler
}
return
}
// WatchChecksHybridHandler wraps the creation of a "checks" plan, additionally setting a hash handler
func WatchChecksHybridHandler(service, state string, stale bool, token, datacenter string, handler watch.HybridHandlerFunc) (wp *watch.Plan, err error) {
if wp, err = WatchChecks(service, state, stale, token, datacenter); wp != nil {
wp.HybridHandler = handler
}
return
}
// WatchEvent wraps the creation of an "event" plan
func WatchEvent(name, token, datacenter string) (*watch.Plan, error) {
return watch.Parse(map[string]interface{}{
"type": "event",
"name": name,
"token": token,
"datacenter": datacenter,
})
}
// WatchEventHandler wraps the creation of an "event" plan, additionally setting an index handler
func WatchEventHandler(name, token, datacenter string, handler watch.HandlerFunc) (wp *watch.Plan, err error) {
if wp, err = WatchEvent(name, token, datacenter); wp != nil {
wp.Handler = handler
}
return
}
// WatchEventHybridHandler wraps the creation of an "event" plan, additionally setting a hash handler
func WatchEventHybridHandler(name, token, datacenter string, handler watch.HybridHandlerFunc) (wp *watch.Plan, err error) {
if wp, err = WatchEvent(name, token, datacenter); wp != nil {
wp.HybridHandler = handler
}
return
}
// WatchConnectRoots wraps the creation of a "connect_roots" plan
func WatchConnectRoots(token, datacenter string) (*watch.Plan, error) {
return watch.Parse(map[string]interface{}{
"type": "connect_roots",
"token": token,
"datacenter": datacenter,
})
}
// WatchConnectRootsHandler wraps the creation of a "connect_roots" plan, additionally setting an index handler
func WatchConnectRootsHandler(token, datacenter string, handler watch.HandlerFunc) (wp *watch.Plan, err error) {
if wp, err = WatchConnectRoots(token, datacenter); wp != nil {
wp.Handler = handler
}
return
}
// WatchConnectRootsHybridHandler wraps the creation of a "connect_roots" plan, additionally setting a hash handler
func WatchConnectRootsHybridHandler(token, datacenter string, handler watch.HybridHandlerFunc) (wp *watch.Plan, err error) {
if wp, err = WatchConnectRoots(token, datacenter); wp != nil {
wp.HybridHandler = handler
}
return
}
// WatchConnectLeaf wraps the creation of a "connect_leaf" plan
func WatchConnectLeaf(service, token, datacenter string) (*watch.Plan, error) {
return watch.Parse(map[string]interface{}{
"type": "connect_leaf",
"service": service,
"token": token,
"datacenter": datacenter,
})
}
// WatchConnectLeafHandler wraps the creation of a "connect_leaf" plan, additionally setting an index handler
func WatchConnectLeafHandler(service, token, datacenter string, handler watch.HandlerFunc) (wp *watch.Plan, err error) {
if wp, err = WatchConnectLeaf(service, token, datacenter); wp != nil {
wp.Handler = handler
}
return
}
// WatchConnectLeafHybridHandler wraps the creation of a "connect_leaf" plan, additionally setting a hash handler
func WatchConnectLeafHybridHandler(service, token, datacenter string, handler watch.HybridHandlerFunc) (wp *watch.Plan, err error) {
if wp, err = WatchConnectLeaf(service, token, datacenter); wp != nil {
wp.HybridHandler = handler
}
return
}
// WatchAgentService wraps the creation of a "agent_service" plan
func WatchAgentService(serviceID string) (*watch.Plan, error) {
return watch.Parse(map[string]interface{}{
"type": "agent_service",
"service_id": serviceID,
})
}
// WatchAgentServiceHandler wraps the creation of a "connect_proxy_config" plan, additionally setting an index handler
func WatchAgentServiceHandler(serviceID string, handler watch.HandlerFunc) (wp *watch.Plan, err error) {
if wp, err = WatchAgentService(serviceID); wp != nil {
wp.Handler = handler
}
return
}
// WatchAgentServiceHybridHandler wraps the creation of a "connect_proxy_config" plan, additionally setting a hash
// handler
func WatchAgentServiceHybridHandler(serviceID string, handler watch.HybridHandlerFunc) (wp *watch.Plan, err error) {
if wp, err = WatchAgentService(serviceID); wp != nil {
wp.HybridHandler = handler
}
return
}
// WatchKey will attempt to create a "key" watch plan based on existing client configuration
func (c *Client) WatchKey(key string, stale bool, handler watch.HandlerFunc) (*watch.Plan, error) {
return WatchKeyHandler(key, stale, c.confToken, c.confDatacenter, handler)
}
// WatchKeyPrefix will attempt to create a "keyprefix" watch plan based on existing client configuration
func (c *Client) WatchKeyPrefix(prefix string, stale bool, handler watch.HandlerFunc) (*watch.Plan, error) {
return WatchKeyPrefixHandler(prefix, stale, c.confToken, c.confDatacenter, handler)
}
// WatchServices will attempt to create a "services" watch plan based on existing client configuration
func (c *Client) WatchServices(stale bool, handler watch.HandlerFunc) (*watch.Plan, error) {
return WatchServicesHandler(stale, c.confToken, c.confDatacenter, handler)
}
// WatchNodes will attempt to create a "nodes" watch plan based on existing client configuration
func (c *Client) WatchNodes(stale bool, handler watch.HandlerFunc) (*watch.Plan, error) {
return WatchNodesHandler(stale, c.confToken, c.confDatacenter, handler)
}
// WatchService will attempt to create a "service" watch plan based on existing client configuration
func (c *Client) WatchService(service, tag string, passingOnly, stale bool, handler watch.HandlerFunc) (*watch.Plan, error) {
return WatchServiceHandler(service, tag, passingOnly, stale, c.confToken, c.confDatacenter, handler)
}
// WatchChecks will attempt to create a "checks" watch plan based on existing client configuration
func (c *Client) WatchChecks(service, state string, stale bool, handler watch.HandlerFunc) (*watch.Plan, error) {
return WatchChecksHandler(service, state, stale, c.confToken, c.confDatacenter, handler)
}
// WatchEvent will attempt to create an "event" watch plan based on existing client configuration
func (c *Client) WatchEvent(name string, handler watch.HandlerFunc) (*watch.Plan, error) {
return WatchEventHandler(name, c.confToken, c.confDatacenter, handler)
}
// WatchConnectRoots will attempt to create a "connect_roots" watch plan based on existing client configuration
func (c *Client) WatchConnectRoots(handler watch.HandlerFunc) (*watch.Plan, error) {
return WatchConnectRootsHandler(c.confToken, c.confDatacenter, handler)
}
// WatchConnectLeaf will attempt to create a "connect_leaf" watch plan based on existing client configuration
func (c *Client) WatchConnectLeaf(service string, handler watch.HandlerFunc) (*watch.Plan, error) {
return WatchConnectLeafHandler(service, c.confToken, c.confDatacenter, handler)
}
// WatchAgentService will attempt to create a "connect_proxy_config" watch plan based on existing client configuration
func (c *Client) WatchAgentService(serviceID string, handler watch.HandlerFunc) (*watch.Plan, error) {
return WatchAgentServiceHandler(serviceID, handler)
}