Versions in this module Expand all Collapse all v1 v1.0.3 May 29, 2026 Changes in this version + var ErrStorageNotFound = errors.New("object not found") + var ErrStoragePrecondition = errors.New("precondition failed") + func NewLeadershipHandler(elector Elector, logger *slog.Logger) http.HandlerFunc + type Elector interface + EnablePeerMode func(caCert []byte) error + GetConfig func() *ElectorConfig + GetLeadershipStatus func() *LeadershipStatus + IsLeader func() bool + LeaderID func() string + Start func(ctx context.Context) error + Stop func() error + UpdateConfig func(newConfig ElectorConfig) error + WaitForLeadership func(ctx context.Context) error + WaitForNextElection func(ctx context.Context, since time.Time) (*LeadershipStatus, error) + type ElectorConfig struct + FrequentInterval time.Duration + InfrequentInterval time.Duration + LeaderTimeout time.Duration + LockfilePath string + OnAcquireLeadership func(ctx context.Context) error + OnLoseLeadership func(ctx context.Context) error + PeerCACert []byte + PeerHealthPath string + PeerMode bool + PeerTimeout time.Duration + ServerAddr string + ServerID string + func (c *ElectorConfig) Validate() error + type HealthServer struct + func NewHealthServer(config HealthServerConfig) (*HealthServer, error) + func (hs *HealthServer) Start(ctx context.Context) error + func (hs *HealthServer) Stop(ctx context.Context) error + type HealthServerConfig struct + BindAddress string + Certificate tls.Certificate + Elector Elector + Logger *slog.Logger + type LeaderRecord struct + LastUpdated time.Time + LeaderAddr string + LeaderID string + Metadata LeaderRecordMetadata + type LeaderRecordMetadata struct + ETag string + type LeadershipStatus struct + ConsecutiveFails int + IsLeader bool + LastElectionTime time.Time + LeaderAddr string + LeaderID string + LeaderLastSeen time.Time + LockfilePath string + ServerID string + type MockStorage struct + func NewMock() *MockStorage + func NewMockStorage(baseDir string) (*MockStorage, error) + func (m *MockStorage) Cleanup() error + func (m *MockStorage) Get(ctx context.Context, key string) ([]byte, string, error) + func (m *MockStorage) PutIfMatch(ctx context.Context, key string, data []byte, etag string) error + type S3Elector struct + func NewS3Elector(opts S3ElectorOptions) (*S3Elector, error) + func (e *S3Elector) EnablePeerMode(caCert []byte) error + func (e *S3Elector) GetConfig() *ElectorConfig + func (e *S3Elector) GetLeadershipStatus() *LeadershipStatus + func (e *S3Elector) IsLeader() bool + func (e *S3Elector) LeaderID() string + func (e *S3Elector) Start(ctx context.Context) error + func (e *S3Elector) Stop() error + func (e *S3Elector) UpdateConfig(newConfig ElectorConfig) error + func (e *S3Elector) WaitForLeadership(ctx context.Context) error + func (e *S3Elector) WaitForNextElection(ctx context.Context, since time.Time) (*LeadershipStatus, error) + type S3ElectorOptions struct + Config *ElectorConfig + Logger *slog.Logger + Storage Storage + type Storage interface + Get func(ctx context.Context, key string) (data []byte, etag string, err error) + PutIfMatch func(ctx context.Context, key string, data []byte, etag string) error