package raft import ( "errors" "git.giftfish.de/ston1th/haproxy-lb/pkg/cluster" "github.com/go-logr/logr" "github.com/hashicorp/raft" ) type Cluster struct { cluster.KV log logr.Logger r *raft.Raft kvm *kv stepdown chan struct{} stop chan struct{} done chan struct{} callbacks cluster.Callbacks id string fatal error } func NewCluster(log logr.Logger) cluster.Cluster { c := &Cluster{log: log} c.Reset() return c } func (c *Cluster) Reset() { kvm := &kv{ m: make(map[string][]byte), } c.KV = kvm c.kvm = kvm c.stepdown = make(chan struct{}, 1) c.stop = make(chan struct{}, 1) c.done = make(chan struct{}, 1) c.fatal = nil } func (c *Cluster) Logger() logr.Logger { return c.log } func (c *Cluster) ID() string { return c.id } func (c *Cluster) SetCallbacks(callbacks cluster.Callbacks) error { c.callbacks = callbacks return c.checkConfig() } 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 }