The time_format, time_utc, and time_location struct tags work correctly
for form/query binding (ShouldBindQuery, ShouldBindForm) but are
completely ignored when using ShouldBindJSON or ShouldBindBodyWithJSON.
encoding/json only understands RFC3339 for time.Time fields, so custom
time formats such as "2006-01-02 15:04:05" or "unix" produce a parse
error like:
parsing time "2001-11-11 11:11:11" as "2006-01-02T15:04:05Z07:00":
cannot parse " 11:11:11" as "T"
This fix replaces the single-pass JSON decode with a field-by-field
decode when the target struct has any time.Time field that carries a
time_format tag. Fields with time_format are parsed by the existing
setTimeField helper (same one used by form binding), so all existing
tag features (time_format, time_utc, time_location, unix/unixmilli/
unixmicro/unixnano) work identically in JSON binding.
Fast path: when the struct has no time_format tags at all, the
original single-pass decoder.Decode path is used (zero overhead).
Fixes#2170
* Add interface to read body bytes in binding
* Add BindingBody implementation for some binding
* Fix to use `BindBodyBytesKey` for key
* Revert "Fix to use `BindBodyBytesKey` for key"
This reverts commit 2c82901ceab6ae53730a3cfcd9839bee11a08f13.
* Use private-like key for body bytes
* Add tests for BindingBody & ShouldBindBodyWith
* Add note for README
* Remove redundant space between sentences
* fix(binding): Expose validator engine used by the default Validator
- Add func ValidatorEngine for returning the underlying validator engine used
in the default StructValidator implementation.
- Remove the function RegisterValidation from the StructValidator interface
which made it immpossible to use a StructValidator implementation without the
validator.v8 library.
- Update and rename test for registering validation
Test{RegisterValidation => ValidatorEngine}.
- Update readme and example for registering custom validation.
- Add example for registering struct level validation.
- Add documentation for the following binding funcs/types:
- Binding interface
- StructValidator interface
- Validator instance
- Binding implementations
- Default func
* fix(binding): Move validator engine getter inside interface
* docs: rm date cmd from custom validation demo