Goelect
Goelect is an open-source, self-contained Golang library designed to facilitate leader election within a distributed system.
Install / Use
/learn @danl5/GoelectREADME
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.
Features
- Independent Operation: No third-party services are required. You don't need to set up or rely on external systems like ZooKeeper or etcd.
- Simplified Integration: Easy to integrate into your existing Golang projects with minimal configuration.
- Supports Novote role:The no-vote node does not participate in the election.
- Highly Available: Built to be fault-tolerant, suitable for systems that require high availability.
How to use
Config
// 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
}
Example
examples/onenode/node.go is a great example of using this goelect package.
Create an Elect instance:
// use the built-in RPC as the transport layer.
rpcTransport, err := rpc.NewRPC(logger)
if err != nil {
return nil, err
}
e, err := goelect.NewElect(
rpcTransport,
// rpc transport config
&rpc.Config{},
&goelect.ElectConfig{
ElectTimeout: 200,
HeartBeatInterval: 150,
ConnectTimeout: 10,
Peers: peerNodes,
// state transition callbacks
CallBacks: &goelect.StateCallBacks{
EnterLeader: enterLeader,
LeaveLeader: leaveLeader,
EnterFollower: enterFollower,
LeaveFollower: leaveFollower,
EnterCandidate: enterCandidate,
LeaveCandidate: leaveCandidate,
},
// self node
Node: goelect.Node{
Address: *nodeAddress,
ID: *nodeAddress,
},
}, logger)
Start the Elect:
err = e.Run()
This is everything we need to do :)
Related Skills
xurl
339.1kA CLI tool for making authenticated requests to the X (Twitter) API. Use this skill when you need to post tweets, reply, quote, search, read posts, manage followers, send DMs, upload media, or interact with any X API v2 endpoint.
diffs
339.1kUse the diffs tool to produce real, shareable diffs (viewer URL, file artifact, or both) instead of manual edit summaries.
kubeshark
11.8kCluster-wide network observability for Kubernetes. Captures L4 packets, L7 API calls, and decrypted TLS traffic using eBPF, with full Kubernetes context. Available to AI agents via MCP and human operators via dashboard.
clearshot
Structured screenshot analysis for UI implementation and critique. Analyzes every UI screenshot with a 5×5 spatial grid, full element inventory, and design system extraction — facts and taste together, every time. Escalates to full implementation blueprint when building. Trigger on any digital interface image file (png, jpg, gif, webp — websites, apps, dashboards, mockups, wireframes) or commands like 'analyse this screenshot,' 'rebuild this,' 'match this design,' 'clone this.' Skip for non-UI images (photos, memes, charts) unless the user explicitly wants to build a UI from them. Does NOT trigger on HTML source code, CSS, SVGs, or any code pasted as text.
