package services import ( "flag" "fmt" "io" "log" "github.com/fgm/izidic" ) const ( PArgs = "args" PHandler = "handler" PName = "name" PProfile = "profile" PQName = "queue-name" PRegion = "region" PURL = "url" PWriter = "writer" SvcClient = "sqs" SvcConsumer = "consumeMessage" SvcFlags = "flags" SvcLister = "lister" SvcLogger = "logger" SvcProducer = "producer" SvcReceiver = "receiver" SvcRedriver = "redriver" ) func FlagsService(dic *izidic.Container) (any, error) { fs := flag.NewFlagSet(dic.MustParam(PName).(string), flag.ContinueOnError) profile := fs.String(PProfile, "test-profile", "The AWS profile") region := fs.String(PRegion, "eu-west-3", "The AWS region to connect to") qName := fs.String(PQName, "dummy-queue", "The queue name") sqsURL := fs.String(PURL, "http://localhost:4566", "The SQS endpoint URL") if err := fs.Parse(dic.MustParam(PArgs).([]string)); err != nil { return nil, fmt.Errorf("cannot obtain CLI args") } dic.Store(PProfile, *profile) dic.Store(PRegion, *region) dic.Store(PURL, *sqsURL) dic.Store(PQName, *qName) return fs, nil } // LoggerService is an izidic.Service also containing a one-time initialization action. func LoggerService(dic *izidic.Container) (any, error) { w := dic.MustParam(PWriter).(io.Writer) log.SetOutput(w) // Support dependency code not taking an injected logger. logger := log.New(w, "", log.LstdFlags) return logger, nil }