forked from baetyl/baetyl-cloud
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
92 lines (81 loc) · 2.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
80
81
82
83
84
85
86
87
88
89
90
91
92
package main
import (
"runtime"
"github.com/baetyl/baetyl-go/v2/context"
"github.com/baetyl/baetyl-go/v2/log"
_ "github.com/go-sql-driver/mysql"
"github.com/baetyl/baetyl-cloud/v2/api"
"github.com/baetyl/baetyl-cloud/v2/common"
"github.com/baetyl/baetyl-cloud/v2/config"
"github.com/baetyl/baetyl-cloud/v2/plugin"
_ "github.com/baetyl/baetyl-cloud/v2/plugin/awss3"
_ "github.com/baetyl/baetyl-cloud/v2/plugin/cache/localcache"
_ "github.com/baetyl/baetyl-cloud/v2/plugin/database"
_ "github.com/baetyl/baetyl-cloud/v2/plugin/decryption"
_ "github.com/baetyl/baetyl-cloud/v2/plugin/default/auth"
_ "github.com/baetyl/baetyl-cloud/v2/plugin/default/csrf"
_ "github.com/baetyl/baetyl-cloud/v2/plugin/default/license"
_ "github.com/baetyl/baetyl-cloud/v2/plugin/default/lock"
_ "github.com/baetyl/baetyl-cloud/v2/plugin/default/pki"
_ "github.com/baetyl/baetyl-cloud/v2/plugin/default/quota"
_ "github.com/baetyl/baetyl-cloud/v2/plugin/default/sign"
_ "github.com/baetyl/baetyl-cloud/v2/plugin/default/task"
_ "github.com/baetyl/baetyl-cloud/v2/plugin/default/transaction"
_ "github.com/baetyl/baetyl-cloud/v2/plugin/kube"
_ "github.com/baetyl/baetyl-cloud/v2/plugin/link/httplink"
_ "github.com/baetyl/baetyl-cloud/v2/plugin/sign"
"github.com/baetyl/baetyl-cloud/v2/server"
)
func main() {
defer plugin.ClosePlugins()
runtime.GOMAXPROCS(runtime.NumCPU())
context.Run(func(ctx context.Context) error {
var cfg config.CloudConfig
err := ctx.LoadCustomConfig(&cfg)
if err != nil {
return err
}
ctx.Log().Debug("cloud config", log.Any("cfg", cfg))
common.SetConfFile(ctx.ConfFile())
a, err := api.NewAPI(&cfg)
if err != nil {
return err
}
sa, err := api.NewSyncAPI(&cfg)
if err != nil {
return err
}
ia, err := api.NewInitAPI(&cfg)
if err != nil {
return err
}
s, err := server.NewAdminServer(&cfg)
if err != nil {
return err
}
s.SetAPI(a)
s.InitRoute()
go s.Run()
defer s.Close()
ctx.Log().Info("admin server starting")
ss, err := server.NewSyncServer(&cfg)
if err != nil {
return err
}
ss.SetSyncAPI(sa)
ss.InitMsgRouter()
ss.Run()
defer ss.Close()
as, err := server.NewInitServer(&cfg)
if err != nil {
return err
}
as.SetAPI(ia)
as.InitRoute()
go as.Run()
defer as.Close()
ctx.Log().Info("init server starting")
ctx.Wait()
return nil
})
}