main.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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/services"
  8. "code.osinet.fr/fgm/sqs_demo/services/redriver"
  9. "code.osinet.fr/fgm/sqs_demo/web"
  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.MustService(services.SvcFlags) // Store generated params before freeze.
  36. dic.Freeze()
  37. return dic
  38. }