main.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package main
  2. import (
  3. "context"
  4. "io"
  5. "log"
  6. "os"
  7. "github.com/fgm/izidic"
  8. services2 "code.osinet.fr/fgm/sqs_demo/back/services"
  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. ctx := context.Background()
  15. dic := Resolve(w, name, args)
  16. lister := dic.MustService(services2.SvcLister).(func(ctx context.Context) string)
  17. qURL := lister(ctx)
  18. producer := dic.MustService(services2.SvcProducer).(func(ctx context.Context, qName string))
  19. producer(ctx, qURL)
  20. log.Printf("exiting cleanly")
  21. return 0
  22. }
  23. func Resolve(w io.Writer, name string, args []string) *izidic.Container {
  24. dic := izidic.New()
  25. dic.Store(services2.PName, name)
  26. dic.Store(services2.PArgs, args)
  27. dic.Store(services2.PWriter, w)
  28. dic.Register(services2.SvcClient, services2.SQSClientService)
  29. dic.Register(services2.SvcFlags, services2.FlagsService)
  30. dic.Register(services2.SvcLister, services2.ListerService)
  31. dic.Register(services2.SvcLogger, services2.LoggerService)
  32. dic.Register(services2.SvcProducer, services2.ProducerService)
  33. dic.MustService(services2.SvcFlags) // Store generated params before freeze.
  34. dic.Freeze()
  35. return dic
  36. }