-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.go
97 lines (80 loc) · 1.51 KB
/
options.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
package registry
import (
"context"
"crypto/tls"
"time"
"github.com/pubgo/lava/core/service"
)
func TTL(dur time.Duration) RegOpt {
return func(o *RegOpts) {
o.TTL = dur
}
}
type Opts struct {
Addrs []string
Timeout time.Duration
Secure bool
TLSConfig *tls.Config
Context context.Context
}
type RegOpts struct {
TTL time.Duration
Context context.Context
}
type WatchOpts struct {
Service string
Context context.Context
}
type DeregOpts struct {
Context context.Context
}
type GetOpts struct {
Timeout time.Duration
Context context.Context
}
type ListOpts struct {
Context context.Context
}
// Addrs is the registry addresses to use
func Addrs(addrs ...string) Opt {
return func(o *Opts) {
o.Addrs = addrs
}
}
func Timeout(t time.Duration) Opt {
return func(o *Opts) {
o.Timeout = t
}
}
// Secure communication with the registry
func Secure(b bool) Opt {
return func(o *Opts) {
o.Secure = b
}
}
// TLSConfig Specify TLS Config
func TLSConfig(t *tls.Config) Opt {
return func(o *Opts) {
o.TLSConfig = t
}
}
func RegisterTTL(t time.Duration) RegOpt {
return func(o *RegOpts) {
o.TTL = t
}
}
func RegisterContext(ctx context.Context) RegOpt {
return func(o *RegOpts) {
o.Context = ctx
}
}
type servicesKey struct{}
// Services is an option that preloads service data
func Services(s map[string][]*service.Service) Opt {
return func(o *Opts) {
if o.Context == nil {
o.Context = context.Background()
}
o.Context = context.WithValue(o.Context, servicesKey{}, s)
}
}