Reader small image

You're reading from  Protocol Buffers Handbook

Product typeBook
Published inApr 2024
PublisherPackt
ISBN-139781805124672
Edition1st Edition
Right arrow
Author (1)
Clément Jean
Clément Jean
author image
Clément Jean

Clément Jean is the CTO of Education for Ethiopia, a start-up focusing on educating K-12 students in Ethiopia. On top of that, he is also an online instructor (on Udemy, Linux Foundation, and others) teaching people about diff erent kinds of technologies. In both his occupations, he deals with technologies such as Protobuf and gRPC and how to apply them to real-life use cases. His overall goal is to empower people through education and technology.
Read more about Clément Jean

Right arrow

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...

lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Protocol Buffers Handbook
Published in: Apr 2024Publisher: PacktISBN-13: 9781805124672

Author (1)

author image
Clément Jean

Clément Jean is the CTO of Education for Ethiopia, a start-up focusing on educating K-12 students in Ethiopia. On top of that, he is also an online instructor (on Udemy, Linux Foundation, and others) teaching people about diff erent kinds of technologies. In both his occupations, he deals with technologies such as Protobuf and gRPC and how to apply them to real-life use cases. His overall goal is to empower people through education and technology.
Read more about Clément Jean