In each of the handlers in an API I have, I first unmarshal the JSON 
request, and then validate the resulting struct.  There are a few cases 
where I am able to pick up a correctable error in the validation code, but 
I'm not sure whether it's good practice to correct the error in the input 
data, or whether it's generally better to simply log the mistake (so that 
the client can be corrected), and return an error.

As a side note, I have a validator interface which is implemented on a 
pointer to each of the structs that I decode into, so it's technically 
quite easy to modify the struct.  However, it will likely not be clear in 
the code that the validator is also modifying data.

What is considered the best practice in this situation? 

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to