go-ozzo / ozzo-validation

An idiomatic Go (golang) validation package. Supports configurable and extensible validation rules (validators) using normal language constructs instead of error-prone struct tags.
MIT License
3.73k stars 224 forks source link

validate struct,err message skip elements "name: " #61

Closed yumin5723 closed 4 years ago

yumin5723 commented 6 years ago

how can i skip the element in err message

yumin5723 commented 6 years ago

how to rewrite error.go function Error()?thanks

qiangxue commented 4 years ago

Because validation.Errors is a map, you can iterate the errors in it and generate your preferred error string.

omarqe commented 4 years ago

Tried to do this one,

val := validation.Errors{
    "name": validation.Validate(user.Name, validation.Required),
    "email": validation.Validate(user.Email, validation.Required, is.Email),
}

for _, e := range val {
    return e
}

return val.Format()

It does terminate name: from the error message, but the bad thing is it skips email and the rest of validation because of the return in the loop. Have no idea what else can I do. Can you provide an example of this?