-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
90 lines (74 loc) · 1.74 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
80
81
82
83
84
85
86
87
88
89
90
package main
import (
"context"
"fmt"
"github.com/CharellKing/ela-lib/config"
"github.com/CharellKing/ela-lib/service/gateway"
"github.com/CharellKing/ela-lib/service/task"
"github.com/CharellKing/ela-lib/utils"
goflags "github.com/jessevdk/go-flags"
"log"
"strings"
"github.com/spf13/viper"
)
func main() {
var err error
cmd := &Cmd{}
// parse args
_, err = goflags.Parse(cmd)
if err != nil {
log.Fatal(err)
return
}
if cmd.ConfigFile == "" {
fmt.Println("Usage: go run main.go --config <config_path> [--gateway] [--tasks] [--task <task name>]")
return
}
viper.SetConfigFile(cmd.ConfigFile)
viper.SetConfigType("yaml")
if err := viper.ReadInConfig(); err != nil {
fmt.Printf("Unable reading config file, %v\n", err)
return
}
var cfg config.Config
if err := viper.Unmarshal(&cfg); err != nil {
fmt.Printf("Unable to decode into struct, %v\n", err)
return
}
utils.InitLogger(&cfg)
ctx := context.Background()
if cmd.Tasks {
taskMgr, err := task.NewTaskMgr(&cfg)
if err != nil {
utils.GetLogger(ctx).WithError(err).Error("create task manager")
return
}
if err := taskMgr.Run(ctx); err != nil {
utils.GetLogger(ctx).WithError(err).Error("run task manager")
return
}
return
}
if cmd.Gateway {
esProxy, err := gateway.NewESGateway(&cfg)
if err != nil {
utils.GetLogger(ctx).Errorf("create task manager %+v", err)
return
}
esProxy.Run()
return
}
if cmd.Task != "" {
taskMgr, err := task.NewTaskMgr(&cfg)
if err != nil {
utils.GetLogger(ctx).WithError(err).Error("create task manager")
return
}
if err := taskMgr.Run(ctx, strings.Fields(cmd.Task)...); err != nil {
utils.GetLogger(ctx).WithError(err).Error("run task manager")
return
}
return
}
return
}