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 think the type shown in the example snippet is correct. It matches the type url.Values. Additionally the proposed type map[string]string causes compilation error.
But... today I have finally spotted big blue note at the very bottom of README:
Because primitive types like int, float, bool, unint and their variants have their default (or zero) values set by Golang, it is not possible to distinguish them from a provided value when decoding/encoding form values. In this case, the value provided by the default option tag will be always applied. (...) In such cases, it is highly recommended to use pointers to allow schema to distinguish between when a form field has no provided value and when a form has a value equal to the corresponding default set by Golang for a particular type.
I'm not sure about encoding, but in case decoding we have all values in the form of map of string list. We can easily distinguish between [""], ["0"] and no entry in the values map.
As a workaround we use following code (adapted to the reported "example") - it works but looks ugly:
value:=input["level"]
// inspect **last** value of the potentially polluted HTTP param (to be consistent// with behavior of other library which parses HTTP parameters)iflen(value) >0&&value[len(value)-1] =="0" {
example.Level=0
}
This proves that it is possible to "distinguish them [default (or zero) values] from a provided value".
Is there an existing issue for this?
Current Behavior
Following code prints the default integer value
10
of fieldLevel
, despite the fact that specifiedlevel
was"0"
.Expected Behavior
Decoder should not ignore user specified integer value even if it is equal to 0. Program should print
0
.Steps To Reproduce
Run the above program.
Anything else?
This bug affects fields of type
int
,uint32
,float64
,... and so on.The text was updated successfully, but these errors were encountered: