gogo / grpc-example

An example of using Go gRPC and tools from the greater gRPC ecosystem together with the GoGo Protobuf Project.
Other
453 stars 87 forks source link

how to replace google's protos when used in grpc gateway request #33

Closed kaisawind closed 4 years ago

kaisawind commented 4 years ago

For example

// The file manager service definition.
service FileManager {
    rpc Hello(google.protobuf.Empty) returns (google.protobuf.Empty) {
        option (google.api.http) = {
            get: "/v1/hello"
        };
        option (grpc.gateway.protoc_gen_swagger.options.openapiv2_operation) = {
            responses: {
                key: "200"
            }
        };
    }
}

the code will be generate just like below

func request_FileManager_Hello_0(ctx context.Context, marshaler runtime.Marshaler, client FileManagerClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
    var protoReq empty.Empty
    var metadata runtime.ServerMetadata

    msg, err := client.Hello(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
    return msg, metadata, err

}

empty.Empty can not be found by go when it be replaced by github.com/gogo/protobuf/types. How can i fix it?

johanbrandhorst commented 4 years ago

This is fixed by using an M import parameter. See https://jbrandhorst.com/post/go-protobuf-tips/ for an example.

kaisawind commented 4 years ago

@johanbrandhorst Maybe I didn't make it clear,I'm sorry about that.

We can use M to fix import packages, but how about really codes? *.pb.go has been changed, but *pb.gw.go not. Please take a look at empty.Empty.

*.pb.go 20200330031600 *pb.gw.go 20200330031624

kaisawind commented 4 years ago

By the way, all *.pb.go and *pb.gw.go imports have been changed.

*.pb.go 20200330032315 *pb.gw.go 20200330032302

johanbrandhorst commented 4 years ago

That one is a bug in the gRPC gateway generator. See https://jbrandhorst.com/post/gogoproto/

kaisawind commented 4 years ago

That one is a bug in the gRPC gateway generator. See https://jbrandhorst.com/post/gogoproto/

Thank you very much.