55 lines
1 KiB
Go
55 lines
1 KiB
Go
package etcd
|
|
|
|
import (
|
|
"errors"
|
|
|
|
"git.giftfish.de/ston1th/vipman/pkg/cluster"
|
|
//"go.etcd.io/etcd/clientv3"
|
|
"github.com/coreos/etcd/clientv3"
|
|
"github.com/go-logr/logr"
|
|
)
|
|
|
|
type Cluster struct {
|
|
logr.Logger
|
|
cluster.KV
|
|
cli *clientv3.Client
|
|
|
|
stepdown chan struct{}
|
|
stop chan struct{}
|
|
done chan struct{}
|
|
callbacks cluster.Callbacks
|
|
|
|
id string
|
|
keyID string
|
|
session bool
|
|
cancelSession func()
|
|
}
|
|
|
|
func NewCluster(log logr.Logger) cluster.Cluster {
|
|
return &Cluster{
|
|
Logger: log,
|
|
KV: &kv{},
|
|
stepdown: make(chan struct{}, 1),
|
|
stop: make(chan struct{}, 1),
|
|
done: make(chan struct{}, 1),
|
|
}
|
|
}
|
|
|
|
func (c *Cluster) SetCallbacks(callbacks cluster.Callbacks) error {
|
|
c.callbacks = callbacks
|
|
return c.checkConfig()
|
|
}
|
|
|
|
func (c *Cluster) ID() string {
|
|
return c.id
|
|
}
|
|
|
|
func (c *Cluster) checkConfig() error {
|
|
if c.callbacks.Leader == nil {
|
|
return errors.New("Leader callback is nil")
|
|
}
|
|
if c.callbacks.Follower == nil {
|
|
return errors.New("Follower callback is nil")
|
|
}
|
|
return nil
|
|
}
|