首页 > 其他 > 详细

导入外部proto获取商品信息

时间:2019-12-19 23:11:33      阅读:111      评论:0      收藏:0      [点我收藏+]

技术分享图片

Models.proto

syntax = "proto3";
package services;

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

Prod.proto

syntax = "proto3";
package services;
import "google/api/annotations.proto";
import "Models.proto"; //引入Models.proto
message ProdRequest {
    int32 prod_id = 1; //传入id
}

message ProdResponse {
    int32 prod_stock = 1; //商品库存
}

message QuerySize {
    int32 size = 1; //页尺寸,这里的1并不是默认值,而是字段的顺序,如果有其他参数就就写2
}

message ProdResponseList {
    repeated ProdResponse prodres = 1; //返回了一堆商品库存,使用了repeated修饰符
}

enum ProdAreas {
    A = 0;
    B = 1;
    C = 2;
}

message ProdRequest2 {
    int32 pro_id = 1; //传入的商品id
    ProdAreas prod_area = 2;
}

service ProdService {
    rpc GetProdStock (ProdRequest) returns (ProdResponse) {
        option (google.api.http) = {
            get: "/v1/prod/{prod_id}" //和request中的prod_id对应,不能写错
        };
    }
    rpc GetProdStock2 (ProdRequest2) returns (ProdResponse) {
        option (google.api.http) = {
            get: "/v1/prod/{prod_id}" //和request中的prod_id对应,不能写错
        };
    }
    rpc GetProdStocks (QuerySize) returns (ProdResponseList){}; //定义了参数是QuerySize
    rpc GetProdInfo(ProdRequest) returns (ProdModel){} //因为引用了Models.proto文件可以直接返回其中定义的结构体模型
}




导入外部proto获取商品信息

原文:https://www.cnblogs.com/hualou/p/12070529.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!