forked from soyking/e3w
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
67 lines (57 loc) · 1.29 KB
/
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
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 (
"flag"
"fmt"
"github.com/coreos/etcd/clientv3"
"github.com/gin-gonic/gin"
"github.com/soyking/e3ch"
"github.com/soyking/e3w/conf"
"github.com/soyking/e3w/routers"
"os"
)
const (
PROGRAM_NAME = "e3w"
PROGRAM_VERSION = "0.0.1"
ETCD_TEST_VERSION = "3.1.0-rc.0+git"
)
var configFilepath string
func init() {
flag.StringVar(&configFilepath, "conf", "conf/config.default.ini", "config file path")
rev := flag.Bool("rev", false, "print rev")
flag.Parse()
if *rev {
fmt.Printf("[%s v%s]\n[etcd %s]\n",
PROGRAM_NAME, PROGRAM_VERSION,
ETCD_TEST_VERSION,
)
os.Exit(0)
}
}
func initClient(config *conf.Config) (*clientv3.Client, *client.EtcdHRCHYClient, error) {
clt, err := clientv3.New(clientv3.Config{
Endpoints: config.EtcdEndPoints,
Username: config.EtcdUsername,
Password: config.EtcdPassword,
})
if err != nil {
return nil, nil, err
}
client, err := client.New(clt, config.EtcdRootKey)
if err != nil {
return nil, nil, err
}
return clt, client, client.FormatRootKey()
}
func main() {
config, err := conf.Init(configFilepath)
if err != nil {
panic(err)
}
etcdClt, client, err := initClient(config)
if err != nil {
panic(err)
}
router := gin.Default()
routers.InitRouters(router, etcdClt, client)
router.Run(":" + config.Port)
}