Validation for web can be a difficult problem. This recipe will explore using closures to support easy mocking of validation functions and to allow flexibility in the type of validation performed when initializing a controller struct as described by the previous recipe.
We'll perform this validation on a struct, but not explore how to populate the struct. We can assume that the data will be populated by parsing a JSON payload, populating explicitly from the form input, or other methods.