Goelect 是一个开源的、自包含的 Golang 库,旨在帮助在分布式系统中进行领导者选举。
Goelect is an open-source Go (Golang) library for leader election. It is heavily influenced by the election component of the Raft implementation. For more details, you can refer to Raft Wiki.
// ElectConfig is a struct that represents the configuration for an election.
type ElectConfig struct {
// Timeout for heartbeat messages, in milliseconds
HeartBeatInterval uint
// Timeout for election messages, in milliseconds
ElectTimeout uint
// Timeout for connecting to peers, in seconds
ConnectTimeout uint
// List of peers in the network
Peers []Node
// Node represents the information of this node
Node Node
// State callbacks
CallBacks *StateCallBacks
// Timeout for callbacks, in seconds
CallBackTimeout int
}examples/onenode/node.go is a great example of using this goelect package.
Create an Elect instance:
…Start the Elect:
err = e.Run()This is everything we need to do :)
暂无开放 Issues,或尚未同步最近议题。