Grpc-go: Update proto package imports to google.golang.org/protobuf/proto

Created on 21 Apr 2020  Â·  7Comments  Â·  Source: grpc/grpc-go

What version of gRPC are you using?

1.28.1

What version of Go are you using (go version)?

go1.13.5 darwin/amd64

What operating system (Linux, Windows, …) and version?

Mac - Catalina

What did you do?

Moved from "github.com/golang/protobuf/proto" to "google.golang.org/protobuf/proto"

What did you expect to see?

Compatibility with grpc-go.

What did you see instead?

WithDetails is expecting github.com/golang/protobuf/proto.Message while thir documentation says that package is depricated.

P2 Feature

Most helpful comment

google.golang.org/protobuf/cmd/protoc-gen-go is the most recent version of the Go protobuf compiler. We (the protobuf devs) recommend using it.

This version of protoc-gen-go does not include support for generating gRPC service definitions. gRPC generation has moved to google.golang.org/grpc/cmd/protoc-gen-go-grpc.

github.com/golang/protobuf/protoc-gen-go v1.4 and higher uses the same code generator as google.golang.org/protobuf/cmd/protoc-gen-go. The two versions produce the same output.

For backwards compatibility, github.com/golang/protobuf/protoc-gen-go includes support for some features which were dropped from the newer compiler, most notably the plugins=grpc flag. If you're currently using github.com/golang/protobuf/protoc-gen-go v1.3 or older, you can upgrade to v1.4 and get the newest code generator without making any other changes.

google.golang.org/grpc/cmd/protoc-gen-go-grpc is the newest gRPC service generator.

Edit: See below; protoc-gen-go-grpc isn't released yet. Use github.com/golang/protobuf/protoc-gen-go for generating gRPC service definitions for now.

By default, protoc-gen-go-grpc includes one backwards incompatible change from the gRPC generator in protoc-gen-go: service implementations must embed the Unimplemented<ServiceName>Server type. This behavior can be disabled with a flag; see:

https://github.com/grpc/grpc-go/blob/master/cmd/protoc-gen-go-grpc/README.md

The protoc-gen-go-grpc generator has just been released, and not all documentation has been updated to reference it. To use it:

OPTIONS=module=example.org/my/module  # or whatever options you need
protoc --go_opt=$OPTIONS --go-grpc_out=$OPTIONS --go_out=. --go-grpc_out=. path/to/foo.proto

Note that you need to pass any options to both code generators (--go_opt and --go-grpc_opt). This is unfortunate, but a limitation of protoc.

All 7 comments

To change the protobuf API that gRPC depends on will be a big undertaking and the team currently does not have the resources to dedicate to it. We also need to make sure that none of our users are broken as we try to make this switch.

I am wondering how many people use protobuf w/o gRPC? Because lack of gRPC support actually makes this release useless.

@alexshtin You can use the protoc-gen-go generator from the v1.4.0 release of golang/protobuf to generate v2 forward-compatible proto and gRPC stubs.

@odsod - apologies if this is a newbie question, but could you provide more details on how to do so? After installing and using v1.4.0 of protoc-gen-go I still get errors ("missing ProtoReflect method") when attempting to use generated types with the google.golang.org/protobuf import. The generated types still import github.com/golang/protobuf/proto. It's very possible I did something wrong.

EDIT: Nevermind, I was doing it wrong. I checked out the v1.4.0 tag, built it, and generated the golang bindings using that version of protoc-gen-go. At that point I was able to use google.golang.org/protobuf

I am really confused about these 2 go packages. I've just tried to generate go code from my proto files using go install github.com/golang/protobuf/protoc-gen-go and go install google.golang.org/protobuf/cmd/protoc-gen-go. The only difference is version in the header:

github.com/golang/protobuf/protoc-gen-go:

//  protoc-gen-go v1.23.0

google.golang.org/protobuf/cmd/protoc-gen-go:

//  protoc-gen-go v1.23.0-devel

And yes, the first one supports gRPC plugin and the second one doesn't. Am I right that both generators are using "...second major revision of the Go protocol buffer API implemented by the google.golang.org/protobuf module." ?

Also noticed that https://github.com/protocolbuffers/protobuf-go/blob/master/go.mod and https://github.com/golang/protobuf/blob/master/go.mod are cross referencing each other. I didn't know that it is even possible.

google.golang.org/protobuf/cmd/protoc-gen-go is the most recent version of the Go protobuf compiler. We (the protobuf devs) recommend using it.

This version of protoc-gen-go does not include support for generating gRPC service definitions. gRPC generation has moved to google.golang.org/grpc/cmd/protoc-gen-go-grpc.

github.com/golang/protobuf/protoc-gen-go v1.4 and higher uses the same code generator as google.golang.org/protobuf/cmd/protoc-gen-go. The two versions produce the same output.

For backwards compatibility, github.com/golang/protobuf/protoc-gen-go includes support for some features which were dropped from the newer compiler, most notably the plugins=grpc flag. If you're currently using github.com/golang/protobuf/protoc-gen-go v1.3 or older, you can upgrade to v1.4 and get the newest code generator without making any other changes.

google.golang.org/grpc/cmd/protoc-gen-go-grpc is the newest gRPC service generator.

Edit: See below; protoc-gen-go-grpc isn't released yet. Use github.com/golang/protobuf/protoc-gen-go for generating gRPC service definitions for now.

By default, protoc-gen-go-grpc includes one backwards incompatible change from the gRPC generator in protoc-gen-go: service implementations must embed the Unimplemented<ServiceName>Server type. This behavior can be disabled with a flag; see:

https://github.com/grpc/grpc-go/blob/master/cmd/protoc-gen-go-grpc/README.md

The protoc-gen-go-grpc generator has just been released, and not all documentation has been updated to reference it. To use it:

OPTIONS=module=example.org/my/module  # or whatever options you need
protoc --go_opt=$OPTIONS --go-grpc_out=$OPTIONS --go_out=. --go-grpc_out=. path/to/foo.proto

Note that you need to pass any options to both code generators (--go_opt and --go-grpc_opt). This is unfortunate, but a limitation of protoc.

@neild, actually we are still iterating on protoc-gen-go-grpc (at v0, so backward incompatible changes may be possible). The gRPC team recommends using github.com/golang/protobuf/protoc-gen-go for generating gRPC services until protoc-gen-go-grpc is released as v1.0.

For more information and to track any potential changes, please see https://github.com/grpc/grpc-go/issues/3669.

Was this page helpful?
0 / 5 - 0 ratings