https://github.com/oastuff/leaderelection
Leadership election in Golang
https://github.com/oastuff/leaderelection
Last synced: 9 months ago
JSON representation
Leadership election in Golang
- Host: GitHub
- URL: https://github.com/oastuff/leaderelection
- Owner: oaStuff
- Created: 2016-02-20T22:45:33.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2016-02-20T23:15:56.000Z (over 10 years ago)
- Last Synced: 2023-03-21T21:51:51.870Z (over 3 years ago)
- Language: Go
- Size: 5.86 KB
- Stars: 1
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# This is a library implementing dynamic leadership election using bully algorithm in GO.
### disclaimer
I am not an expert implementing bully algorithm. This was just a 'play project' learning Golang.
#### Installation
```sh
go get github.com/oaStuff/leaderElection
```
### Usage
The usage is very simple. All node (application running on a seperate machine or a separate process) that wish to participate in coordinated operation and allowing only one process become leader must do
* register a callback with the library
* specify the multicast address to use
* specify the network interface to use
### Example
```go
func myCallback(state int){
if state == election.LEADER {
fmt.Println("Hey !, I am the leader and can do or setup things to become a leader")
} else if state == election.FOLLOWER {
fmt.Println("I am a follower")
}
}
func main() {
bChan := make(chan bool)
err := election.RegisterCallback(myCallback,"239.0.1.1:9999","eth1")
if err != nil{
panic(err)
}
<-bChan
}
```