main.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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/services"
  8. "code.osinet.fr/fgm/sqs_demo/back/web"
  9. )
  10. func main() {
  11. os.Exit(int(main2(os.Stdout, os.Args[0], os.Args[1:])))
  12. }
  13. func main2(w io.Writer, name string, args []string) (exitCode byte) {
  14. dic := Resolve(w, name, args)
  15. h := dic.MustService(services.SvcHttp).(*gin.Engine)
  16. addr := dic.MustParam(services.PAddr).(string)
  17. if err := h.Run(addr); err != nil {
  18. return 1
  19. }
  20. return 0
  21. }
  22. func Resolve(w io.Writer, name string, args []string) *izidic.Container {
  23. dic := izidic.New()
  24. dic.Store(services.PName, name)
  25. dic.Store(services.PArgs, args)
  26. dic.Store(services.PWriter, w)
  27. dic.Register(services.SvcFlags, services.FlagsService)
  28. dic.Register(services.SvcLister, services.ListerService)
  29. dic.Register(services.SvcLogger, services.LoggerService)
  30. dic.Register(services.SvcHttp, web.HttpPreviewerService)
  31. dic.Register(services.SvcRenderer, web.RendererService)
  32. dic.MustService(services.SvcFlags) // Store generated params before freeze.
  33. dic.Freeze()
  34. return dic
  35. }