protoc:libprotoc 3.12.4
protoc-gen-go v1.25.0-devel
macos go version go1.14.4 darwin/amd64
macos catalina 10.15.5
git clone https://github.com/grpc/grpc-go.git
cd grpc-go/examples/helloworld/helloworld
protoc -I. --go-grpc_out=. --go_out=. ./helloworld.proto
cat google.golang.org/grpc/examples/helloworld/helloworld/helloworld_grpc.pb.go
found this code
// GreeterServer is the server API for Greeter service.
// All implementations must embed UnimplementedGreeterServer
// for forward compatibility
type GreeterServer interface {
// Sends a greeting
SayHello(context.Context, *HelloRequest) (*HelloReply, error)
mustEmbedUnimplementedGreeterServer()
}
what is the mustEmbedUnimplementedGreeterServer method?
As the name says, your service implementation must embed the helloworld pb.UnimplementedGreeterServer in order to be passed to the RegisterGreeterService function. This is being discussed to potentially change in #3669. Note that you are using an unreleased version of the code generator and it may change in non-backward compatible ways.
@dfawley Thanks, which version could be work now?
I have run in to this too.
Having a method inside the obvious (and documented) interface to implement as an instruction seems like an awful code smell.
@garydevenay see the (very, very long) discussion in #3669 if you want to appreciate why we're doing this. And as documented in the README, you can have the legacy behavior with a command-line option if you really want it.
@seifchen Sorry I missed your comment earlier. Back then it was advisable to keep using the legacy tool at https://github.com/golang/protobuf, but we released v1.0 of the codegen in this repo recently, so it should be used instead: https://github.com/grpc/grpc-go/releases/tag/cmd%2Fprotoc-gen-go-grpc%2Fv1.0.0
For those like me who have no idea what "embedding" means, can you provide a hint as to what we should do? I get this error for the test app here though that test app otherwise seems to deploy fine. Its not clear where I'm going wrong, so any hints would be greatly appreciated.
@josegonzalez
I believe
// server is used to implement helloworld.GreeterServer.
type server struct{
// Embed the unimplemented server
helloworld.UnimplementedGreeterServer
}
is what you are looking for. correct me if I am wrong @dfawley
@manikanta-talanki - correct, thank you for assisting.
protoc --go-grpc_out=require_unimplemented_servers=false[,other options...]:. can solve this problem.
That worked great, thank y ou @manikanta-talanki !
@yujintang - This works, but your binary will fail to compile if you add methods to your service(s) and regenerate/recompile. That is why we have the embedding requirement by default. We recommend against using this option.
@manikanta-talanki thank you so much.
So honestly, there are a lot of us who think that the newly added "feature" is totally useless. We want it to fail to compile after we've added methods to our services that haven't been implemented yet. We understand that client and server versions both have to be updated when you add a service method, but that's not a problem.
@manikanta-talanki thank you this solved my problem
@teuber789 if you prefer the old behavior of breakages when new methods are added, embed the UnsafeFooService interface instead.
@manikanta-talanki thanks a bunch
Most helpful comment
@josegonzalez
I believe
is what you are looking for. correct me if I am wrong @dfawley