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. "code.osinet.fr/fgm/sqs_demo/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(services.SvcLister).(func(ctx context.Context) string)
  17. qURL := lister(ctx)
  18. producer := dic.MustService(services.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(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.MustService(services.SvcFlags) // Store generated params before freeze.
  34. dic.Freeze()
  35. return dic
  36. }