-
Notifications
You must be signed in to change notification settings - Fork 0
/
transport.go
61 lines (51 loc) · 1.16 KB
/
transport.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
package gossipcache
import (
"darvaza.org/gossipcache/transport"
"github.com/hashicorp/memberlist"
)
// revive:disable:cognitive-complexity
// NewGossipTransportConfig creates a transport.Config from a Config
func NewGossipTransportConfig(conf *Config) (*transport.Config, error) {
// revive:enable:cognitive-complexity
tc := conf.Transport
if tc == nil {
tc = &transport.Config{}
}
// Context
if tc.Context == nil {
tc.Context = conf.Context
}
// Logger
if tc.Logger == nil {
tc.Logger = conf.Logger
}
// BindAddress
if len(tc.BindAddress) == 0 {
s := conf.Memberlist.BindAddr
if s == "" {
s = "0.0.0.0"
}
tc.BindAddress = []string{s}
}
// BindPort
if tc.BindPort == 0 {
tc.BindPort = conf.Memberlist.BindPort
}
if err := tc.SetDefaults(); err != nil {
return nil, err
}
return tc, nil
}
// NewGossipTransport creates a transport.Transport from a Config
func NewGossipTransport(conf *Config) (memberlist.Transport, *transport.Config, error) {
// Config
tc, err := NewGossipTransportConfig(conf)
if err != nil {
return nil, tc, err
}
t, err := transport.New(tc)
if err != nil {
return nil, tc, err
}
return t, tc, nil
}