This is an example project mirroring my example project for prost in rust
protoc installation instructions
Just in case the link goes dead, here's the instructions
Linux, using apt or apt-get, for example:
$ apt install -y protobuf-compiler
$ protoc --version # Ensure compiler version is 3+
MacOS, using Homebrew:
$ brew install protobuf
$ protoc --version # Ensure compiler version is 3+
This build can likely be automated by a Makefile, but I want to show what's involved since go's tooling can't handle this on its own like rust's can.
$ go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
This can also be handles by a build tool like bazel, but it seems simple enough to include a single option in your protofile if you're not working in a largely polyglot environment.
See items.proto for an example
The following script uses find
to automate adding the protobuf files to the command.
$ protoc -I=protos/ \
--go_out=src/protos \
$(find protos -iname "*.proto")
Or check them in. If you do check them in, however, it would begood to have a CI process that can recompile them and ensure that the generated protos and the existing code for the branch are in sync or error if not.
$ go run ./src/main.go