广阔天地大有作为

你想拥有什么,就去追求什么

30 Jul 2018

grpc转换为http对外服务

grpc转换为http对外服务

grpc支持将协议转换成http对外服务,数据通过post json提交 相对于普通的grpc服务,只需要在定义pb时稍作修改即可

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
syntax = "proto3";

package helloworld;
import "google/api/annotations.proto";

service srv {
    rpc Say(HelloReq) returns (HelloResp){
        option (google.api.http) = {
            post: "/say/hello"                  
            body: "*"
        };
    }
}

调用:curl -X POST http://127.0.0.1:8080/say/hello -d {} 相对于普通pb多了 import "google/api/annotations.proto";

1
2
3
4
option (google.api.http) = {
            post: "/say/hello"                  
            body: "*"
        };