forked from QubitProducts/bamboo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
zk-test.go
48 lines (37 loc) · 862 Bytes
/
zk-test.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
43
44
45
46
47
48
package main
import (
"bufio"
"flag"
"fmt"
"os"
"github.com/samuel/go-zookeeper/zk"
conf "github.com/QubitProducts/bamboo/configuration"
"github.com/QubitProducts/bamboo/qzk"
)
func showEvents(evts chan zk.Event) {
ok := true
for ok {
ev, isOk := <-evts
ok = isOk
if ev.State != zk.StateDisconnected {
fmt.Printf("a change occurred: %+v\n", ev)
}
}
}
var configFilePath string
var config conf.Configuration
func init() {
flag.StringVar(&configFilePath, "config", "config/development.json", "Full path of the configuration JSON file")
}
func main() {
config, err := conf.FromFile(configFilePath)
if err != nil {
panic(err)
}
evts, quit := qzk.ListenToZooKeeper(config.Bamboo.Zookeeper, true)
go showEvents(evts)
reader := bufio.NewReader(os.Stdin)
_, _ = reader.ReadString('\n')
quit <- true
fmt.Printf("exiting!\n")
}