Search code examples
goprotocol-buffersgrpcprotocgrpc-gateway

Cannot make grpc-gateway .gw.pb and there is no error


I've written this simple go server and client which client sends two numbers, and the server replies with the sum, and it works. Now I'm trying to set up a grpc-gateway using grpc API configuration and change the client's request from GRPC to rest.

I am using this tutorial and in the below section, I can not create gw, while there is no error:

protoc -I/usr/local/include -I. \
  -I$GOPATH/src \
  -I$GOPATH/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis \
  --grpc-gateway_out=logtostderr=true,grpc_api_configuration=path/to/your_service.yaml:. \
  path/to/your_service.proto

I used this:

protoc -I/usr/local/include -I.   -I$GOPATH/src   -I$GOPATH/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis --grpc-gateway_out=logtostderr=true,grpc_api_configuration=$GOPATH/src/grpc-test/sum.yaml:. ./sum.proto

and after this problem I searched and I found this way, which is neither working (no error and no output!):

protoc -I/usr/local/include -I. -I$GOPATH/src -I$GOPATH/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis --plugin=protoc-gen-grpc-gateway=$GOPATH/bin/protoc-gen-grpc-gateway  --grpc-gateway_out=logtostderr=true,grpc_api_configuration=sum.yaml:. ./sum.proto

I run this in the grpc-test directory which has the below tree:

grpc-test tree

So, what am I doing wrong?

Edit: so this is my sum.yaml:

type: google.api.Service
config_version: 3

http:
  rules:
    - selector: example.YourService.Echo
      post: /v1/example/echo
      body: "*"

And this is sum.proto:

syntax = "proto3";


service ComputeSum {
    rpc ComputeSum (SumRequest) returns (ResultReply) {
    }
}

message SumRequest {
    int32 firstOperand = 1;
    int32 secondOperand = 2;
}

message ResultReply {
    int32 result = 1;
}

Solution

  • The problem is with the selector in, it should be ComputeSum.ComputeSum. I asked this question in grpc-channel in Gophers slack, and Johan Brandhorst helped me with this.