Command:
protoc \
--go_out=. \
--go_opt=paths=source_relative \
--go-grpc_out=. \
--go-grpc_opt=paths=source_relative \
proto/user.proto
Command ini digunakan untuk generate file Go dari definisi Protocol Buffers di proto/user.proto.
Output yang Dihasilkan
Biasanya command ini akan menghasilkan:
proto/user.pb.go
proto/user_grpc.pb.go
Penjelasan Flag
--go_out=.
Generate kode Go untuk message protobuf.
--go_opt=paths=source_relative
Menjaga output file tetap relatif terhadap lokasi file .proto.
--go-grpc_out=.
Generate kode Go untuk service gRPC.
--go-grpc_opt=paths=source_relative
Menjaga output file gRPC tetap relatif terhadap lokasi file .proto.
Prerequisite
Pastikan plugin berikut sudah terinstall:
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
Pastikan juga $GOPATH/bin sudah ada di PATH.