If user accidentally adds whitespaces in param ex.:
a := struct {
DateField time.Time `json:"date_field" binding:required`
}
Body:
{
"date_field": "2022-06-02 "
}
is there any way to remove extra spaces before binding to struct to prevent possible errors?
Comment From: dansimau
I also have the same requirement.
This can be achieved with custom bindings, but I've found myself copy/pasting a lot of internal code just to recreate the builtin binders but with a TrimSpace.
Maybe it would make more sense to be able to hook into the existing binding via pre/post hooks.
Comment From: therox
Or it could be something like strip_whitespace=True
in pydantic.
Comment From: Cookiery
Maybe you can handle it in the frontend.
Comment From: jledesma84
@therox did you find anything interesting to solve this?
Comment From: therox
@jledesma84 No, I didn't. I have to use reflect manually to get access to structure field's data.