You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am unable to call the same instance of ServiceA when implementing command-line operations using the flag library.
Specific Situation:
When triggering the addAdminCommand, the NewServiceA in the invoke function is called again, as evidenced by the logger being re-initialized and producing new output.
When initializing ServiceA, its Status field is set to "A". After modifying it to "B" through the command, an HTTP request to retrieve the Status field of ServiceA still returns "A".
Additional Note:
I'm posting this in Discussions because I am unsure whether the issue lies with dig or flag, or if it is simply a limitation of command-line operations being unable to share state across executions.
main.go:
// 1. DI
container.Provide(NewServiceA)
// 2. Pass container to command line tools (flag library)
addAdminCommand(container)
// 3. run app with container
RunApp(container)
serviceA.go:
type ServiceA {
Status string
}
func NewServiceA() *ServiceA {
logger.Info("Init ServieA")
return &ServiceA{Status: "A"}
}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I am unable to call the same instance of
ServiceA
when implementing command-line operations using theflag
library.Specific Situation:
addAdminCommand
, theNewServiceA
in theinvoke
function is called again, as evidenced by the logger being re-initialized and producing new output.ServiceA
, itsStatus
field is set to"A"
. After modifying it to"B"
through the command, an HTTP request to retrieve theStatus
field ofServiceA
still returns"A"
.Additional Note:
I'm posting this in Discussions because I am unsure whether the issue lies with
dig
orflag
, or if it is simply a limitation of command-line operations being unable to share state across executions.main.go:
serviceA.go:
addAdminCommand.go:
Beta Was this translation helpful? Give feedback.
All reactions