-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
57 lines (46 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
package main
import (
"context"
"flag"
"fmt"
logicServer "github.com/EAHITechnology/cage/server"
"github.com/EAHITechnology/cage/utils"
"github.com/EAHITechnology/raptor/config"
"github.com/EAHITechnology/raptor/elog"
"github.com/EAHITechnology/raptor/server"
)
var (
configFilePath = flag.String("config", "./conf/server_config.toml", "config file path")
)
func main() {
flag.Parse()
ctx := context.Background()
ctx, cancel := context.WithCancel(ctx)
s, err := server.NewServer(ctx, "", *configFilePath)
if err != nil {
fmt.Println("NewServer err:", err.Error())
return
}
// injection lazy loading function
InitConfigFunc := func(ctx context.Context, config config.ConfigParser) {
if err := config.Unmarshal(&utils.Config); err != nil {
elog.Elog.Errorf("config Unmarshal err:", err.Error())
return
}
}
InitServerFunc := func(ctx context.Context, config config.ConfigParser) {
if err := logicServer.InitServer(ctx); err != nil {
elog.Elog.Errorf("InitServer err:", err.Error())
return
}
elog.Elog.Info("InitServer success")
}
InitBackend := func(ctx context.Context, config config.ConfigParser) {
logicServer.InitBackend(ctx)
}
s.AfterInit(InitConfigFunc, InitServerFunc, InitBackend)
if err := s.Run(ctx, cancel); err != nil {
fmt.Println("NewServer err:", err.Error())
return
}
}