Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Client side code #72

Open
rytsh opened this issue Dec 6, 2024 · 1 comment
Open

Client side code #72

rytsh opened this issue Dec 6, 2024 · 1 comment

Comments

@rytsh
Copy link

rytsh commented Dec 6, 2024

I am using these imports to call health check

	"buf.build/gen/go/grpc/grpc/connectrpc/go/grpc/health/v1/healthv1connect"
	healthv1 "buf.build/gen/go/grpc/grpc/protocolbuffers/go/grpc/health/v1"

But if I use this one and mix with grpc imports than I get issue.

panic: proto: file "grpc/health/v1/health.proto" is already registered
                previously from: "buf.build/gen/go/grpc/grpc/protocolbuffers/go/grpc/health/v1"
                currently from:  "google.golang.org/grpc/health/grpc_health_v1"
        See https://protobuf.dev/reference/go/faq#namespace-conflict

Could you show how to call this server code?

[EDIT]
Generated code and replaced to original package to use it, can we do it same in this repo?
https://github.com/worldline-go/grpc/blob/main/health/v1/healthv1connect/health.connect.go#L27

@jhump
Copy link
Member

jhump commented Dec 9, 2024

But if I use this one and mix with grpc imports than I get issue.

This is a known issue with Protobuf Go -- you can only use a single package that represents the same generated proto sources. You could disable this error via the GOLANG_PROTOBUF_REGISTRATION_CONFLICT=warn environment variable (as mentioned in the link at the end of the error message).

If you are using both gRPC and Connect in the same binary, you could just use the gRPC packages for the health checks. If you want to use the same transport as for other Connect stubs to the same backend service, then I'd recommend not using code-gen for now.

So instead of generating that large amount of code in https://github.com/worldline-go/grpc/blob/main/health/v1/healthv1connect/health.connect.go#L27, you really only need this snippet. You can then invoke CallUnary on that *connect.Client value.

As far as adding API to this repo to provide an RPC client, that is certainly the right long-term direction. So I'll leave this issue open and only close it when we've added that. But for the short-term, instead of waiting on that change and a release, I'd stick with the suggestion in the above paragraph.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants