grpc-gateway runtime version conflict

2.2k Views Asked by At

from last few days the protoc generator is generating code with v2 version of github.com/grpc-ecosystem/grpc-gateway. I want to keep using github.com/grpc-ecosystem/grpc-gateway v1.16.0. I am unable to remove the v2 version which is causing conflict. I tried removing from go.mod, clearing from $GOPATH. I suppose my protoc generator is not able to use v1 version. Kindly guide me as how shall I sync the grpc-gateway runtime package.

Using below commands to generate the messages and service

protoc -I . --go-grpc_out=. api/protobuf-spec/catalog_fetch/*.proto
protoc -I . --grpc-gateway_out=logtostderr=true:. api/protobuf-spec/catalog_fetch/*.proto

Note: It is generating both grpc.pb.go file and pb.go file, which is further causing issue.

cannot use mux (type *"github.com/grpc-ecosystem/grpc-gateway/runtime".ServeMux) as type *"github.com/grpc-ecosystem/grpc-gateway/v2/runtime".ServeMux ```
2

There are 2 best solutions below

1
On

I have spent 3 hours debugging the exact same problem.

You have to remove the binary from your GOPATH and GOROOT.

For simplicity, just use which protoc-gen-grpc-gateway.

This should point you to the binary protoc is using under the hood. Remove it and rerun go get -u github.com/grpc-ecosystem/grpc-gateway/[email protected].

0
On

I think you have installed the v2 version of the generator. Unfortunately, you cannot use v1.16.0 with newer versions of the go protobuf generators. If you want to keep using v1.16.0, you can download the generator from the releases page https://github.com/grpc-ecosystem/grpc-gateway/releases/tag/v1.16.0.