-
Notifications
You must be signed in to change notification settings - Fork 1
/
node_option.go
61 lines (50 loc) · 1.39 KB
/
node_option.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 rafting
import (
"fmt"
"time"
"github.com/danielgatis/go-discovery"
"github.com/sirupsen/logrus"
"k8s.io/client-go/kubernetes"
)
type NodeOption func(*Node)
func WithLogger(logger logrus.FieldLogger) NodeOption {
return func(n *Node) {
n.logger = logger
}
}
func WithDataDir(dataDir string) NodeOption {
return func(n *Node) {
n.dataDir = dataDir
}
}
func WithStaticDiscovery(peers []string) NodeOption {
return func(n *Node) {
n.discovery = discovery.NewDummyDiscovery(peers, n.logger)
}
}
func WithMdnsDiscovery() NodeOption {
return func(n *Node) {
n.discovery = discovery.NewMdnsDiscovery(fmt.Sprintf("raft:%s", n.id), "_raft._tcp", "local.", n.port, n.logger)
}
}
func WithK8sDiscovery(clientset kubernetes.Interface, namespace string, portName string, labels map[string]string) NodeOption {
return func(n *Node) {
n.discovery = discovery.NewK8sDiscovery(clientset, namespace, portName, labels, n.logger)
}
}
func WithDiscovery(discovery discovery.Discovery) NodeOption {
return func(n *Node) {
n.discovery = discovery
}
}
func WithDiscoveryLookupInterval(interval time.Duration) NodeOption {
return func(n *Node) {
n.discoveryLookupInterval = interval
}
}
func WithSerializer(marshalFn func(interface{}) ([]byte, error), unmarshalFn func([]byte, interface{}) error) NodeOption {
return func(n *Node) {
n.marshalFn = marshalFn
n.unmarshalFn = unmarshalFn
}
}