forked from tquach/zk-rest-api
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
44 lines (35 loc) · 740 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
43
44
package main
import (
"flag"
"log"
"net/http"
"os"
"time"
"github.com/samuel/go-zookeeper/zk"
"github.com/tquach/zk-rest-api/strflag"
)
// Global constants.
const (
DefaultZKTimeout = 10 * time.Second
)
var (
addr = flag.String("addr", ":8080", "address and port to listen on")
zkHosts strflag.StringSlice
)
func main() {
flag.Parse()
if len(zkHosts) == 0 {
flag.Usage()
os.Exit(1)
}
conn, _, err := zk.Connect(zkHosts, DefaultZKTimeout)
if err != nil {
log.Fatalf("zk fail: %s", err)
}
ctrl := &Controller{zkConn: conn}
log.Printf("Starting service on %s...", *addr)
log.Fatal(http.ListenAndServe(*addr, ctrl))
}
func init() {
flag.Var(&zkHosts, "zk", "Comma-separated list of hosts to zookeeper.")
}