/
atlantis-routerapi.go
67 lines (53 loc) · 1.49 KB
/
atlantis-routerapi.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package main
import (
"atlantis/routerapi/api"
"atlantis/routerapi/zk"
"github.com/jigish/go-flags"
)
type RouterApi struct {
*flags.Parser
opts *RouterApiOptions
APIListenAddress string
ZkServerAddress string
ZkNeedConfig bool
}
type RouterApiOptions struct {
APIListenAddress string `short:"A" long:"listen-address" description:"The address for the API to listen on"`
ZkServerAddress string `short:"Z" long:"zk-address" description:"The address of the ZK server"`
InitZK string `short:"I" long:"init-zk" description:"Initialize zk?"`
}
func NewRouterApi() *RouterApi {
opts := &RouterApiOptions{}
return &RouterApi{Parser: flags.NewParser(opts, flags.Default), opts: opts}
}
func (rapi *RouterApi) setConfig(options RouterApiOptions) {
rapi.APIListenAddress = options.APIListenAddress
rapi.ZkServerAddress = options.ZkServerAddress
rapi.ZkNeedConfig = (options.InitZK != "")
}
func (rapi *RouterApi) loadConfig() {
rapi.Parse()
if rapi.opts.APIListenAddress != "" {
rapi.APIListenAddress = rapi.opts.APIListenAddress
} else {
rapi.APIListenAddress = "99999"
}
if rapi.opts.ZkServerAddress != "" {
rapi.ZkServerAddress = rapi.opts.ZkServerAddress
} else {
rapi.ZkServerAddress = "28080"
}
if rapi.opts.InitZK == "y" {
rapi.ZkNeedConfig = true
}
}
func main() {
rapi := NewRouterApi()
rapi.loadConfig()
rapi.run()
}
func (rapi *RouterApi) run() {
api.Init(rapi.APIListenAddress)
zk.Init(rapi.ZkServerAddress, rapi.ZkNeedConfig)
api.Listen()
}