2017-02-15 17:09:28 +03:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
|
|
|
"github.com/Difrex/zoorest/rest"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2017-06-22 17:06:39 +03:00
|
|
|
zk string
|
|
|
|
listen string
|
|
|
|
path string
|
|
|
|
mc bool
|
|
|
|
mcHosts string
|
|
|
|
mcPrefix string
|
2017-02-15 17:09:28 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
// init ...
|
|
|
|
func init() {
|
|
|
|
flag.StringVar(&zk, "zk", "127.0.0.1:2181", "Zk servers. Comma separated")
|
|
|
|
flag.StringVar(&listen, "listen", "127.0.0.1:8889", "Address to listen")
|
|
|
|
flag.StringVar(&path, "path", "/", "Zk root path")
|
2017-06-22 17:06:39 +03:00
|
|
|
flag.BoolVar(&mc, "mc", false, "Enable memcached support")
|
|
|
|
flag.StringVar(&mcHosts, "mchosts", "127.0.0.1:11211", "Memcached servers. Comma separated")
|
|
|
|
flag.StringVar(&mcPrefix, "mcprefix", "zoorest", "Memcached key prefix")
|
2017-02-15 17:09:28 +03:00
|
|
|
flag.Parse()
|
|
|
|
}
|
|
|
|
|
|
|
|
// main ...
|
|
|
|
func main() {
|
|
|
|
var z rest.Zk
|
2017-06-22 17:06:39 +03:00
|
|
|
hosts := getSlice(zk, ",")
|
2017-02-15 17:09:28 +03:00
|
|
|
z.Hosts = hosts
|
|
|
|
conn, err := z.InitConnection()
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2017-06-22 17:06:39 +03:00
|
|
|
var zoo rest.ZooNode
|
|
|
|
zoo.Path = path
|
|
|
|
zoo.Conn = conn
|
|
|
|
zoo.Zoo = z
|
|
|
|
|
|
|
|
var MC rest.MC
|
|
|
|
MC.Hosts = getSlice(mcHosts, ",")
|
|
|
|
MC.Prefix = mcPrefix
|
|
|
|
MC.Enabled = mc
|
|
|
|
MC.Client = MC.InitConnection()
|
|
|
|
|
|
|
|
zoo.MC = MC
|
2017-02-15 17:09:28 +03:00
|
|
|
|
|
|
|
rest.Serve(listen, zoo)
|
|
|
|
}
|
2017-06-22 17:06:39 +03:00
|
|
|
|
|
|
|
// getSlice returm slice
|
|
|
|
func getSlice(s string, delimeter string) []string {
|
|
|
|
return strings.Split(s, ",")
|
|
|
|
}
|