Distributed Services With Go - gogoproto on linux

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

2 Likes

Hi,

I work on a mac and I had to use this command :

protoc api/v1/*.proto \
		--gogoslick_out=plugins=grpc:. \
		--proto_path=$$(go list -f '{{ .Dir }}' -m github.com/gogo/protobuf) \
		--proto_path=.

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 ?

To be fair, there is an old README in the git repo (https://github.com/gogo/protobuf/blob/master/README) descripting usage as

protoc --gogo_out=. -I=.:github.com/gogo/protobuf/protobuf *.proto
2 Likes

You didn’t have the second beta right? I believe I fixed this.

2 Likes

I’m on the second beta right now, sadly the problem still exists (I’m on Linux).

Used this command to fix:
protoc --gogoslick_out=. -I=. -I=${GOPATH}/src -I=${GOPATH}/src/github.com/gogo/protobuf/gogoproto *.proto

also my log.proto is updated:

syntax = "proto3";

package log.v1;

import "github.com/gogo/protobuf/gogoproto/gogo.proto";

option (gogoproto.marshaler_all) = true;
option (gogoproto.unmarshaler_all) = true;
option (gogoproto.sizer_all) = true;

message Record {
  bytes value = 1;
  uint64 offset = 2;
}
3 Likes

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.

2 Likes

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.

2 Likes

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.

1 Like

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.