goelect

package module
v0.0.0-...-c03468e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 12, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

README

goelect

A library for the election process with no third-party dependencies.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Elect

type Elect struct {
	// contains filtered or unexported fields
}

Elect contains information about an election

func NewElect

func NewElect(cfg *ElectConfig, logger log.Logger) (*Elect, error)

NewElect creates a new Elect instance

func (*Elect) Errors

func (e *Elect) Errors() <-chan error

Errors returns a receive-only channel of type error from the Elect struct

func (*Elect) Run

func (e *Elect) Run() error

Run is the main function of the Elect struct

type ElectConfig

type ElectConfig struct {
	// Timeout for connecting to peers
	ConnectTimeout uint
	// List of peers in the network
	Peers []Node
	// Node information
	Node Node
	// State callbacks
	CallBacks *StateCallBacks
	// Timeout for callbacks
	CallBackTimeout int
}

ElectConfig is a struct that represents the configuration for an election.

type Node

type Node struct {
	// ID of the node
	ID string
	// Address of the node
	Address string
	// NoVote indicates whether the node is able to vote
	NoVote bool
	// Tags associated with the node
	Tags map[string]string
}

Node is a struct that represents an elect node

type StateCallBacks

type StateCallBacks struct {
	// EnterLeader is a callback function to be called when entering the leader state
	EnterLeader StateHandler
	// LeaveLeader is a callback function to be called when leaving the leader state
	LeaveLeader StateHandler
	// EnterFollower is a callback function to be called when entering the follower state
	EnterFollower StateHandler
	// LeaveFollower is a callback function to be called when leaving the follower state
	LeaveFollower StateHandler
	// EnterCandidate is a callback function to be called when entering the candidate state
	EnterCandidate StateHandler
	// LeaveCandidate is a callback function to be called when leaving the candidate state
	LeaveCandidate StateHandler
}

StateCallBacks is a struct to hold state callbacks

type StateHandler

type StateHandler func(ctx context.Context, st model.StateTransition) error

Directories

Path Synopsis
cmd
examples
internal
log
rpc

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL