The project
In this chapter, we are going to create a protoc plugin that generates code validating the user input for a phone number and email address in our AddressBook application. This involves creating a Protobuf custom option and writing the actual plugin logic to generate the validation code.
The overall goal of this chapter is to have a CLI that checks the user input. Let’s say the user enters the following command:
$ go run main.go add --kind per --name Clement --phone 111
It should return the following error:
error: 111 is not a valid phone number
Similarly, for emails, let’s say the user enters the following:
$ go run main.go add --kind per --name Clement --email 111
It should return the following error:
error: 111 is not a valid email
And obviously, this should also work for company contacts.
On top of that, we will add an option to the protoc plugin that lets us choose which regexp
rule to use in order to check the phone number. The...