main.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package main
  2. import (
  3. "io"
  4. "os"
  5. "github.com/fgm/izidic"
  6. "github.com/gin-gonic/gin"
  7. "code.osinet.fr/fgm/sqs_demo/back/web"
  8. "code.osinet.fr/fgm/sqs_demo/back/services"
  9. "code.osinet.fr/fgm/sqs_demo/back/services/redriver"
  10. )
  11. func main() {
  12. os.Exit(int(main2(os.Stdout, os.Args[0], os.Args[1:])))
  13. }
  14. func main2(w io.Writer, name string, args []string) (exitCode byte) {
  15. dic := Resolve(w, name, args)
  16. h := dic.MustService(services.SvcHttp).(*gin.Engine)
  17. addr := dic.MustParam(services.PAddr).(string)
  18. if err := h.Run(addr); err != nil {
  19. return 1
  20. }
  21. return 0
  22. }
  23. func Resolve(w io.Writer, name string, args []string) *izidic.Container {
  24. dic := izidic.New()
  25. dic.Store(services.PName, name)
  26. dic.Store(services.PArgs, args)
  27. dic.Store(services.PWriter, w)
  28. dic.Register(services.SvcClient, services.SQSClientService)
  29. dic.Register(services.SvcFlags, services.FlagsService)
  30. dic.Register(services.SvcLister, services.ListerService)
  31. dic.Register(services.SvcLogger, services.LoggerService)
  32. dic.Register(services.SvcProducer, services.ProducerService)
  33. dic.Register(services.SvcRedriver, redriver.RedriverService)
  34. dic.Register(services.SvcHttp, web.HttpService)
  35. dic.Register(services.SvcRenderer, web.RendererService)
  36. dic.MustService(services.SvcFlags) // Store generated params before freeze.
  37. dic.Freeze()
  38. return dic
  39. }