This error comes newer versions of the protoc-gen-grpc-go
compiler. Server implementations must now be forward-compatible.
Before this change, whenever you registered a server implementation, you would do something like this:
pb.RegisterFooBarServiceServer(
server,
&FooBarServer{}, // or whatever you use to construct the server impl
)
Which would result in a compile-time error in case your server has some missing method implementations.
With the newer proto compiler version, forward-compatibility becomes opt-out, which means two things:
you must now embed UnimplementedFooBarServiceServer
, as the error message suggests. As I said, this will not produce compiler errors when you do not explicitly implement new methods (this is what forward compatibility means). Though it will result in a run-time error with codes.Unimplemented
if you attempt to call an RPC that you didn't (or forgot) to explicitly implement.
you can still opt-out of forward compatibility by embedding instead UnsafeFooBarServiceServer
(with Unsafe
prefix). This interface simply declares the mustEmbedUnimplementedFooBarServiceServer()
method which makes the error in the question go away, without forgoing a compiler errors in case you didn't explicitly implement the new handlers.
So for example:
// Implements the grpc FooBarServiceServer
type FooBarService struct {
grpc.UnsafeFooBarServiceServer // consciously opt-out of forward compatibility
// other fields
}
You can also generate code without forward compatibility by setting an option on protoc-gen-grpc-go
plugin (source):
protoc --go-grpc_out=require_unimplemented_servers=false:.
Note the :.
after the --go-grpc_out
option is used to set the path element.