-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathmain.go
67 lines (57 loc) · 1.61 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"
"github.com/busgo/pink/collector"
"github.com/busgo/pink/conf"
"github.com/busgo/pink/db"
"github.com/busgo/pink/db/repository"
"github.com/busgo/pink/executor"
"github.com/busgo/pink/http"
"github.com/busgo/pink/http/handler"
"github.com/busgo/pink/node"
"github.com/busgo/pink/pkg/bus"
"github.com/busgo/pink/pkg/etcd"
"github.com/busgo/pink/pkg/log"
"github.com/busgo/pink/schedule"
"go.uber.org/dig"
"time"
)
var confFile = flag.String("conf", "./app.yaml", "conf file")
func BuildApp() *dig.Container {
app := dig.New()
_ = app.Provide(func() (*conf.AppConf, error) {
return conf.NewAppConf(*confFile)
})
_ = app.Provide(db.NewDB)
_ = app.Provide(func(app *conf.AppConf) (*etcd.Cli, error) {
return etcd.NewEtcdCli(&etcd.CliConfig{
Endpoints: app.Etcd.Endpoints,
UserName: app.Etcd.UserName,
Password: app.Etcd.Password,
DialTimeout: time.Second * time.Duration(app.Etcd.DialTimeout),
})
})
// repository
_ = app.Provide(repository.NewExecuteSnapshotRepository)
_ = app.Provide(bus.NewEventBus)
_ = app.Provide(collector.NewPinkCollector)
_ = app.Provide(executor.NewPinkGroupManaged)
_ = app.Provide(executor.NewPinkExecutor)
_ = app.Provide(schedule.NewPinkScheduler)
_ = app.Provide(node.NewPinkNode)
_ = app.Provide(handler.NewPinkWebHandler)
_ = app.Provide(http.NewHttpService)
return app
}
func main() {
flag.Parse()
app := BuildApp()
err := app.Invoke(func(s *http.Service) error {
log.Infof("http service start run......")
return s.Run()
})
if err != nil {
log.Errorf("the pink service start fail %+v", err)
panic(err)
}
}