-
Notifications
You must be signed in to change notification settings - Fork 4.5k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
mustEmbedUnimplemented*** method appear in grpc-server #3794
Comments
As the name says, your service implementation must embed the helloworld |
@dfawley Thanks, which version could be work now? |
I have run in to this too. |
@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 // 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 |
@manikanta-talanki thanks a bunch |
add this it will fix the issue |
This was already suggested above, and as was also mentioned above: "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." |
it works for me, thank you! type SimpleService struct {
pb.UnimplementedSimpleServer
} |
Update: This seems to be an issue with the Go linters instead of with protobuf. The program still compiles as expected. My apologies for the noise
|
Is this a custom linter you have? We run |
I'm using JetBrain's GoLand IDE (version 2020.3), so I'm not sure if the IDE uses a custom linter or not. |
Seconded @marcusljx Goland seems to be complaining, but I can still build / run correctly. Might be worth opening a bug with Jetbrains |
I am trying to use composition for my server. I have a struct that implements one of the methods. I add that to my main struct. When my main struct also includes Unimplemented... the compiler throws an error that says my methods are ambiguous. This is because the same method exists at the same level in both my code and in the Unimplemented... code. How do I include both my struct and the other one without the collision? |
Unfortunately, I think the only way around this would be to declare the method(s) on the main struct, and dispatch to the proper implementation beneath it: type PartialFooService struct {}
func (p *PartialFooService) SomeMethod(...) { ... }
type MainFooService struct {
PartialFooService
pb.UnimplementedFooServer
}
func (m *MainFooService) SomeMethod(...) { return m.PartialFooService.SomeMethod(...) } OR embed the |
The first option is not DRY, breaks the isolation with separate services, and generally defeats the purpose of composition. The second option clearly says it is entirely discouraged. |
version
protoc:libprotoc 3.12.4
protoc-gen-go v1.25.0-devel
go version?
macos go version go1.14.4 darwin/amd64
What operating system (Linux, Windows, …) and version?
macos catalina 10.15.5
What did you do?
result
found this code
what is the mustEmbedUnimplementedGreeterServer method?
The text was updated successfully, but these errors were encountered: