-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
79 lines (73 loc) · 1.32 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
68
69
70
71
72
73
74
75
76
77
78
79
package main
import (
"kimo/agent"
"kimo/config"
"kimo/server"
"os"
"github.com/cenkalti/log"
"github.com/urfave/cli"
)
func init() {
log.DefaultHandler.SetLevel(log.DEBUG)
}
func main() {
app := cli.NewApp()
var cfg = config.NewConfig()
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "config, c",
Value: "/etc/kimo.yaml",
Usage: "configuration file path",
},
cli.BoolFlag{
Name: "debug, d",
Usage: "enable debug log",
},
}
app.Before = func(c *cli.Context) error {
err := cfg.LoadConfig(c.GlobalString("config"))
if err != nil {
log.Errorf("Cannot read config: %s\n", err)
}
if c.IsSet("debug") {
cfg.Debug = true
}
if cfg.Debug {
log.SetLevel(log.DEBUG)
} else {
log.SetLevel(log.INFO)
}
return nil
}
app.Commands = []cli.Command{
{
Name: "agent",
Usage: "run agent",
Action: func(c *cli.Context) error {
a := agent.NewAgent(&cfg.Agent)
err := a.Run()
if err != nil {
return err
}
return nil
},
},
{
Name: "server",
Usage: "run server",
Action: func(c *cli.Context) error {
s := server.NewServer(&cfg.Server)
s.Config = &cfg.Server
err := s.Run()
if err != nil {
return err
}
return nil
},
},
}
err := app.Run(os.Args)
if err != nil {
log.Errorf("Error occured: %s\n", err.Error())
}
}