Context:
Using a custom Binder and Validator in Echo Framework. The binder use a signature of (interface{}, echo.Context)
, but a pointer is always passed and checked by echo.DefaultBinder
.
I'm having trouble validating an array of struct for some reason, when an array is passed for some unknown reason. Therefore, I'm trying to validate each elements in the interface, if this interface is an Array or a Slice.
Problem:
I cannot find a way to both cast the interface
to a value
instead of a pointer
and iterate trough the values of this array to validate each of them.
My Code so far:
func (cb *CustomBinder) Bind(i interface{}, c echo.Context) error {
db := new(echo.DefaultBinder)
validate := validator.New()
if err := db.Bind(i, c); err != nil {
return err
}
kind := reflect.ValueOf(i).Elem().Kind()
if kind == reflect.Array || kind == reflect.Slice {
// ... Iteration and Validation
} else {
if err := validate.Struct(i); err != nil {
return err
}
}
return nil
}