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
fillValues function returns error if header with int value is not set.
type ControllerPostParams struct {
IntegerInJsonBody int json:"integerInJsonBody" validate:"min=1,max=100000"
stringInHeader string header:"X-String,omitempty"
}
The error occurs in switch case
case reflect.Int, reflect.Int64:
var v int64
if v, err = strconv.ParseInt(value, 10, 64); err != nil {
return err
}
sv.SetInt(v)
return nil
in case of an empty header value = "" strconv.ParseInt throws an error. I guess the same problem will occur in all number based switch cases from fillValues. I recommended to check if the header is set and otherwise exit the loop.
I know you can also set header:"-" in the struct tags, but this can be easily forgotten.
Additionally we initialise our params with defaults and httpheader.Decode overwrites everything if we do not set header:"-", which adds a lot of overhead in our stuct tags.
My proposal:
add an option that struct fields are left unharmed and are not overwritten with empty strings if no header is present.
The text was updated successfully, but these errors were encountered:
fillValues function returns error if header with int value is not set.
type ControllerPostParams struct {
IntegerInJsonBody int
json:"integerInJsonBody" validate:"min=1,max=100000"
stringInHeader string
header:"X-String,omitempty"
}
The error occurs in switch case
case reflect.Int, reflect.Int64:
var v int64
if v, err = strconv.ParseInt(value, 10, 64); err != nil {
return err
}
sv.SetInt(v)
return nil
in case of an empty header value = "" strconv.ParseInt throws an error. I guess the same problem will occur in all number based switch cases from fillValues. I recommended to check if the header is set and otherwise exit the loop.
I know you can also set header:"-" in the struct tags, but this can be easily forgotten.
Additionally we initialise our params with defaults and httpheader.Decode overwrites everything if we do not set header:"-", which adds a lot of overhead in our stuct tags.
My proposal:
add an option that struct fields are left unharmed and are not overwritten with empty strings if no header is present.
The text was updated successfully, but these errors were encountered: