-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathcluster.go
57 lines (45 loc) · 1.16 KB
/
cluster.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
package lrmr
import (
"fmt"
"github.com/ab180/lrmr/cluster"
"github.com/ab180/lrmr/coordinator"
"github.com/creasty/defaults"
)
// Cluster represents a lrmr cluster.
type Cluster struct {
cluster.Cluster
ClusterOptions cluster.Options
coordinator coordinator.Coordinator
}
// WithCoordinator sets coordinator for cluster.
func WithCoordinator(crd coordinator.Coordinator) func(*Cluster) {
return func(c *Cluster) {
c.coordinator = crd
}
}
// WithClusterOptions sets cluster options.
func WithClusterOptions(options cluster.Options) func(*Cluster) {
return func(c *Cluster) {
c.ClusterOptions = options
}
}
// Close closes coordinator after closing cluster.
func (c *Cluster) Close() error {
if err := c.Cluster.Close(); err != nil {
return err
}
return c.coordinator.Close()
}
func newDefaultCoordinator() (coordinator.Coordinator, error) {
crd, err := coordinator.NewEtcd([]string{`"127.0.0.1:2379"`}, `lrmr/`, coordinator.EtcdOptions{})
if err != nil {
return nil, fmt.Errorf("connect coordinator: %w", err)
}
return crd, nil
}
func defaultClusterOptions() (o cluster.Options) {
if err := defaults.Set(&o); err != nil {
panic(err)
}
return
}