page 20: … protoc command…
I had to additionally run the following go get commands in order to be able to compile protobuf code using gogo protobuf on a linux machine:
go get github.com/gogo/protobuf/proto
go get github.com/gogo/protobuf/jsonpb
go get github.com/gogo/protobuf/protoc-gen-gogo
go get github.com/gogo/protobuf/gogoproto
I don’t use Mac but it would be nice to mention that the setup on linux is different or point the readers to the git repo for installation instruction. https://github.com/gogo/protobuf/tree/master
Notice the gogoslick_out flag. I had to use that instead of the gogo_out flag described in the book.
The readme file says :
protoc-gen-gogofast (same as gofast, but imports gogoprotobuf)
protoc-gen-gogofaster (same as gogofast, without XXX_unrecognized, less pointer fields)
protoc-gen-gogoslick (same as gogofaster, but with generated string, gostring and equal methods)
But indeed, I didn’t saw the last paragraph “Most Speed and most customization” describing the command you suggest.
So I guess, it’s not a matter of Mac or Linux. Maybe the gogo/protobuf changed is usage ?
I’m on Linux. Just double checked on Linux and Mac and both worked.
# I've deleted all protoc-gen-go* executables to check that it fails.
[tj@computer ServeRequestsWithgRPC]$ protoc api/v1/*.proto \
--gogo_out=Mgogoproto/gogo.proto=github.com/gogo/protobuf/proto:. \
--proto_path=$(go list -f '{{ .Dir }}' -m github.com/gogo/protobuf) \
--proto_path=.
protoc-gen-gogo: program not found or is not executable
Please specify a program using absolute path or make sure the program is available in your PATH system variable
--gogo_out: protoc-gen-gogo: Plugin failed with status code 1.
# I install the executables.
[tj@computer ServeRequestsWithgRPC]$ go get github.com/gogo/protobuf/...@v1.3.1
# Check that it can find the executable and succeeds.
[tj@computer ServeRequestsWithgRPC]$ protoc api/v1/*.proto --gogo_out=Mgogoproto/gogo.proto=github.com/gogo/protobuf/proto:. --proto_path=$(go list -f '{{ .Dir }}' -m github.com/gogo/protobuf) --proto_path=.
[tj@computer ServeRequestsWithgRPC]$ # worked
Maybe something is up with your PATH so the executables aren’t found or something.
I was running in to similar problems and created a VS Code Dev Container to make it reproducible:
protoc won’t compile, resulting in error:
$(go list -f ‘{{ .Dir }}’ -m github.com/gogo/protobuf): warning: directory does not exist. gogoproto/gogo.proto: File not found. api/v1/log.proto:5:1: Import “gogoproto/gogo.proto” was not found or had errors.
Where gogo.proto is actually there but has errors.
I was having the same issue (on Arch Linux), and it turned out to be a permission issue. Make sure you have permission to run the protoc executable, and check the permissions for your working directory.
Hey y’all, I’ve switched the book to use github.com/golang/protobuf because of the release of Go’s protobuf APIv2, gogoprotobuf lacking ownership and projects moving away from using gogoprotobuf: https://github.com/gogo/protobuf/issues/691. This update will be in a subsequent beta release.