44 lines
862 B
Go
44 lines
862 B
Go
package cluster
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
|
|
"git.giftfish.de/ston1th/haproxy-lb/pkg/config"
|
|
"github.com/go-logr/logr"
|
|
)
|
|
|
|
var (
|
|
ErrNotLeader = errors.New("not leader")
|
|
ErrKeyNotFound = errors.New("key not found")
|
|
ErrPrefixNotFound = errors.New("prefix not found")
|
|
ErrRestart = errors.New("restart")
|
|
)
|
|
|
|
type Cluster interface {
|
|
Start(*config.Config) error
|
|
SetCallbacks(Callbacks) error
|
|
Stepdown()
|
|
Stop()
|
|
Reset()
|
|
}
|
|
|
|
type KV interface {
|
|
Get(k string) ([]byte, error)
|
|
GetPrefix(k string) (map[string][]byte, error)
|
|
Set(k string, v []byte) error
|
|
Delete(k string) error
|
|
}
|
|
|
|
type CallbackContext interface {
|
|
KV
|
|
Logger() logr.Logger
|
|
ID() string
|
|
Fatal(error)
|
|
}
|
|
|
|
type Callbacks struct {
|
|
Leader func(context.Context, CallbackContext)
|
|
Follower func(context.Context, CallbackContext)
|
|
Cleanup func(context.Context, CallbackContext)
|
|
}
|