main.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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/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. ctx := context.Background()
  16. dic := Resolve(w, name, args)
  17. lister := dic.MustService(services.SvcLister).(func(ctx context.Context) string)
  18. qURL := lister(ctx)
  19. producer := dic.MustService(services.SvcProducer).(func(ctx context.Context, qName string))
  20. producer(ctx, qURL)
  21. log.Printf("exiting cleanly")
  22. return 0
  23. }
  24. func Resolve(w io.Writer, name string, args []string) *izidic.Container {
  25. dic := izidic.New()
  26. dic.Store(services.PName, name)
  27. dic.Store(services.PArgs, args)
  28. dic.Store(services.PWriter, w)
  29. dic.Register(services.SvcClient, services.SQSClientService)
  30. dic.Register(services.SvcFlags, services.FlagsService)
  31. dic.Register(services.SvcLister, services.ListerService)
  32. dic.Register(services.SvcLogger, services.LoggerService)
  33. dic.Register(services.SvcMessageStore, redriver.MessageStoreService)
  34. dic.Register(services.SvcProducer, services.ProducerService)
  35. dic.MustService(services.SvcFlags) // Store generated params before freeze.
  36. dic.Freeze()
  37. return dic
  38. }