vipman/pkg/raft/cluster.go
2020-11-15 00:30:35 +01:00

36 lines
701 B
Go

package raft
import (
"errors"
"git.giftfish.de/ston1th/vipman/pkg/cluster"
"github.com/hashicorp/raft"
)
type Cluster struct {
kv *KV
r *raft.Raft
stepdown chan struct{}
stop chan struct{}
done chan struct{}
Callbacks cluster.Callbacks
}
func NewCluster(callbacks cluster.Callbacks) (cluster.Cluster, error) {
if callbacks.Leader == nil {
return nil, errors.New("Leader is nil")
}
if callbacks.Follower == nil {
return nil, errors.New("Follower is nil")
}
return &Cluster{
kv: &KV{
m: make(map[string][]byte),
},
stepdown: make(chan struct{}, 1),
stop: make(chan struct{}, 1),
done: make(chan struct{}, 1),
Callbacks: callbacks,
}, nil
}