grpc-gateway

3 篇文章 0 订阅

第三方库

https://github.com/grpc-ecosystem/grpc-gateway

 安装步骤

go get -u github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway
go get -u github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger
go get -u github.com/golang/protobuf/protoc-gen-go

 proto文件头部需要引入import "google/api/annotations.proto";

在rpc出需要添加option

syntax="proto3";
package services;
import "google/api/annotations.proto";
import "models.proto";

message OrderRequest {
    OrderMain order_main = 1;
}

message OrderResponse {
    string status = 1;
    string message = 2;
}

service OrderService{
    rpc NewOrder(OrderRequest) returns(OrderResponse){
        option (google.api.http) = {
            post: "/v1/orders"
            body:"order_main"
        };
    }
}

生成文件(一个proto文件需要执行下面2个命令,一个是生成proto的go文件,一个是生成gateway文件)

protoc --go_out=plugins=grpc:../services  Prod.proto
protoc  --grpc-gateway_out=logtostderr=true:../services Prod.proto

 访问使用  路径为 /v1/orders

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值