Validation for web can be a problem. This recipe will explore using closures to support the easy mocking of validation functions and to allow flexibility in the type of validation performed when initializing a controller structure as described by the previous recipe.
We'll perform this validation on a structure, but not explore how to populate the structure. We can assume that the data will be populated by parsing a JSON payload, populating explicitly from the form input, or other methods.
How to do it...
The following steps cover the writing and running of your application:
- From your Terminal or console application,createa new directory called~/projects/go-programming-cookbook/chapter8/validation, and navigate to this directory.
- Run the following command:
$ go mod init github.com/PacktPublishing/Go-Programming-Cookbook-Second...