package main import ( "box-cost/api" "box-cost/bus" "box-cost/conf" "box-cost/db" "box-cost/log" "flag" "go.uber.org/dig" "infish.cn/comm" ) 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.NewMongoDB) _ = app.Provide(db.NewRedisClient) _ = app.Provide(bus.NewNatsBus) _ = app.Provide(api.NewHttpService) return app } func main() { comm.AppMongoMiration() flag.Parse() app := BuildApp() err := app.Invoke(func(svc *api.Service, bus *comm.NatsBus) error { go bus.Run(nil) svc.Run() return nil }) if err != nil { log.Errorf("the pink service start fail %+v", err) panic(err) } }