protoc is the Protocol Buffer compiler used with gRPC. It processes a .proto contract and generates language-specific code, reducing serialization and service-integration boilerplate while preserving strong typing across languages. section 11.5
Listing 11.14 A basic proto3 file for a chat server
syntax = "proto3"; #1
package chat; #2
import "google/protobuf/timestamp.proto"; #3
option go_package = "./ch11"; #4
message CommentRequest { #5
string username = 1;
string text = 2;
google.protobuf.Timestamp sent = 3;
}
message CommentResponse {
int32 commentLength = 1;
int32 previousCommentCount = 2;
}
service ChatService { #6
rpc RouteComments(Comment) returns (CommentMeta) {} #6
}
A proto3 definition declares the package, imports shared types, selects a Go output package, defines messages, and declares a gRPC service. section 11.5
protoc - --go_out=. --go-grpc-out=._protos/chat.proto
Run protoc with Go and gRPC output plugins to generate the client and service scaffolding from a .proto file. section 11.5



