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
In your examples, the whole point was to show error validation errors, but in real-world applications, it's rarely the use case. As a GO API developer, I'm not sure how to handle empty validation error maps.
Please let me know if you think it's a good example and I could add them to a PR. 😄
err := v.ValidateJSON()
if err.Get("_error") != "" {
log.Print(err)
http.Error(w, "Error happened processing the request", http.StatusInternalServerError)
return
}
if len(err) != 0 {
validationErr := map[string]interface{}{"validationError": err}
json.NewEncoder(w).Encode(validationErr)
return
}
The text was updated successfully, but these errors were encountered:
There's a bit of a difference between the conventional way go unmarshalls JSON into a struct and PHP json_decodes. I was noticing a lot of my validation rules really don't matter (numeric, for example) b/c if passed a string, Go won't be able to unmarshall type string into an int32 so I always get that error back instead of the validation error saying it needs to be an integer (er, numeric).
You "can" dynamically parse JSON in Go. I'd like to test if that is a viable solution.
In your examples, the whole point was to show error validation errors, but in real-world applications, it's rarely the use case. As a GO API developer, I'm not sure how to handle empty validation error maps.
Please let me know if you think it's a good example and I could add them to a PR. 😄
The text was updated successfully, but these errors were encountered: