-2

I have a protobuf definition of an interface. I autogenerate client functions for that interface using protoc --go_out=... --go-grpc_out=... file.proto.

The autogenerated functions all have this code snippet:

if err != nil {
    return nil, err
}
return out, nil // out is what the server returned to this client

I want all autogenerated functions to not have this check, and instead directly return out, err. Is there a protoc or go-grpc_out option that alters autogeneration behaviour in this way?

selamba
  • 384
  • 4
  • 12
  • 1
    I doubt there's a way to override that. If there was an error there's no guarantee the return value is valid, so it is not something you should rely on being able to inspect. – JimB Aug 03 '22 at 14:00
  • @JimB That's not really grpc's business. All I want is for that function to pass along whatever the server returned. All of it – selamba Aug 03 '22 at 14:03
  • 1
    that's the idiomatic way – Matteo Aug 03 '22 at 14:04
  • 1
    @Matteo and legacy code I'm dealing with broke that idiom. Again, not grpc's business – selamba Aug 03 '22 at 14:05
  • If there this "worked before" - then use a previous gprc plugin verion that generated code that did not include this check. Or hand edit the generated code. You only need to re-generate the go-code if your protobuf definitions change and since you are dealing with a legacy situation, this should not be an issue. – colm.anseo Aug 03 '22 at 15:43
  • Take the generated code, alter it to your purpose and run with it. The warning about generated code is purely to let you know, not that you can not change it.... – Norbert Aug 03 '22 at 16:35

1 Answers1

2

Is there a protoc or go-grpc_out option that alters autogeneration behaviour in this way?

No.

But if your goal is to see what was sent over the network, your approach won't work anyway, even if there were such an option.

What will get a bit closer, though, is a client interceptor, which can give you access to the gRPC payload before it's handled by the client function.

But even this won't give you the raw network data. If you get an invalid gRPC message, even that will be handled before passed to the interceptor. If that's what you need, you'll want some sort of network layer proxy.

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189