-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.go
58 lines (48 loc) · 1.55 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
package gossip
import (
"context"
"time"
"github.com/hashicorp/memberlist"
registry "github.com/pubgo/lug/registry"
)
type secretKey struct{}
type addressKey struct{}
type configKey struct{}
type advertiseKey struct{}
type connectTimeoutKey struct{}
type connectRetryKey struct{}
// helper for setting registry opts
func setRegistryOption(k, v interface{}) registry.Opt {
return func(o *registry.Opts) {
if o.Context == nil {
o.Context = context.Background()
}
o.Context = context.WithValue(o.Context, k, v)
}
}
// Secret specifies an encryption key. The value should be either
// 16, 24, or 32 bytes to select AES-128, AES-192, or AES-256.
func Secret(k []byte) registry.Opt {
return setRegistryOption(secretKey{}, k)
}
// Address to bind to - host:port
func Address(a string) registry.Opt {
return setRegistryOption(addressKey{}, a)
}
// Config sets *memberlist.Config for configuring gossip
func Config(c *memberlist.Config) registry.Opt {
return setRegistryOption(configKey{}, c)
}
// The address to advertise for other gossip members to connect to - host:port
func Advertise(a string) registry.Opt {
return setRegistryOption(advertiseKey{}, a)
}
// ConnectTimeout sets the registry connect timeout. Use -1 to specify infinite timeout
func ConnectTimeout(td time.Duration) registry.Opt {
return setRegistryOption(connectTimeoutKey{}, td)
}
// ConnectRetry enables reconnect to registry then connection closed,
// use with ConnectTimeout to specify how long retry
func ConnectRetry(v bool) registry.Opt {
return setRegistryOption(connectRetryKey{}, v)
}