post提交主订单数据(gateway)实现httpapi

models.proto

syntax = "proto3";
package services;
import "google/protobuf/timestamp.proto"; //引入timestamp的proto文件

//商品模型
message ProdModel {
    int32 prod_id = 1;
    string prod_name = 2;
    float prod_price = 3;
}

message OrderMain {
    int32 order_id = 1; //订单id,数字
    int32 user_id = 3; //购买者id
    float order_money = 4; //商品金额
    google.protobuf.Timestamp order_time = 5; //定义时间戳字段
}

Orders.proto 封装json数据到post请求

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


message OrderRequest {
    OrderMain order_main = 1; //声明request入参是OrderMain类型的字段
}

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" //body内容是order_main字段,与OrderRequest要对应,通过http请求获取参数
        };
    }
}




猜你喜欢

转载自www.cnblogs.com/hualou/p/12070226.html