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 building a bunch of independent microservices of which everyone uses the same set of Arguments (some with default values).
I then override some of the default values in the services (because some services need different default values than the majority) before parsing the arguments, to get an idea:
While overriding bool values I noticed that values that have a default value of "true" in the struct, can't be overridden to "false" but overriding a "false" default value to "true" works.
Seems a bit strange to handle this differently, is this on purpose?
The text was updated successfully, but these errors were encountered:
Oh, very interesting. This might a bug due to false being the zero value for bool. The way go-arg determines whether a value has been overridden is by checking whether it is different from the zero value. One way you could work around this would be by using *bool rather than bool. This would be a bit ugly, I know, but might be a short-term solution for you. In the mean time I will consider how to resolve this more thoroughly.
Okay thanks, I actually just removed the default tags and only used the override by accessing the fields.
But i have another question, I just saw, that default values for slices and maps aren't supported, is this planned for the future or not possible? I can imagine that it would be tricky via tags, but it seems possible via assigning the default value by accessing the field.
The best way to do it at the moment is to implement TextUnmarshaler, as in:
type Map map[string]string
func (m *Map) UnmarshalText(b []byte) error {
// decode the string into a map using whatever encoding you prefer -- e.g. json
}
var args struct {
ArgumentName Map
}
The problem I ran into was that there was no canonical way to deserialize a default string into a map or list. I might just pick one and implement it in v2 of this library (see #197)
Reference
I am building a bunch of independent microservices of which everyone uses the same set of Arguments (some with default values).
I then override some of the default values in the services (because some services need different default values than the majority) before parsing the arguments, to get an idea:
The Args struct is defined globally for everyone:
The actual Issue
While overriding bool values I noticed that values that have a default value of "true" in the struct, can't be overridden to "false" but overriding a "false" default value to "true" works.
Seems a bit strange to handle this differently, is this on purpose?
The text was updated successfully, but these errors were encountered: