main.go 792 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package main
  2. import (
  3. "box-cost/api"
  4. "box-cost/bus"
  5. "box-cost/conf"
  6. "box-cost/db"
  7. "box-cost/log"
  8. "flag"
  9. "go.uber.org/dig"
  10. "infish.cn/comm"
  11. )
  12. var confFile = flag.String("conf", "./app.yaml", "conf file")
  13. func BuildApp() *dig.Container {
  14. app := dig.New()
  15. _ = app.Provide(func() (*conf.AppConf, error) {
  16. return conf.NewAppConf(*confFile)
  17. })
  18. _ = app.Provide(db.NewMongoDB)
  19. _ = app.Provide(db.NewRedisClient)
  20. _ = app.Provide(bus.NewNatsBus)
  21. _ = app.Provide(api.NewHttpService)
  22. return app
  23. }
  24. func main() {
  25. comm.AppMongoMiration()
  26. flag.Parse()
  27. app := BuildApp()
  28. err := app.Invoke(func(svc *api.Service, bus *comm.NatsBus) error {
  29. go bus.Run(nil)
  30. svc.Run()
  31. return nil
  32. })
  33. if err != nil {
  34. log.Errorf("the pink service start fail %+v", err)
  35. panic(err)
  36. }
  37. }