-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
42 lines (33 loc) · 816 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package main
import (
"flag"
"fmt"
"strings"
"time"
"github.com/mattmcmurray/gomob/gomob"
)
var (
members = flag.String("peers", "", "Comma seperated list of peers. Only one known peer is required. Gossip will handle the rest.")
isMasterNode = flag.Bool("master", false, "Define as master node")
numNodes = flag.Int("num_nodes", 1, "The number of nodes in the cluster")
)
func init() {
flag.Parse()
}
func main() {
m := make([]string, 0)
if len(*members) > 0 {
m = strings.Split(*members, ",")
}
s := gomob.ConsensusSettings{
Members: m,
Master: *isMasterNode,
NumNodes: *numNodes,
}
err := gomob.WaitOnConsensus(&s)
if err != nil {
panic(err)
}
// The code here will execute only when all nodes have reached synchronicity
fmt.Println("Consensus at:", time.Now())
}