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文件可以直接返回其中定义的结构体模型
}
原文地址:https://www.cnblogs.com/hualou/p/12070529.html
时间: 2024-11-09 06:03:45