proto文件

goods.proto

  1. syntax = "proto3";
  2. import "google/protobuf/empty.proto";
  3. option go_package = ".;proto";
  4. //用户服务
  5. service Goods{
  6. //商品相关接口
  7. //商品列表
  8. rpc GoodsList(GoodsFilterRequest) returns(GoodsListResponse);
  9. //批量获取商品信息
  10. //现在用户提交订单有多个商品,你得批量查询商品的信息吧
  11. rpc BatchGetGoods(BatchGoodsIdInfo) returns(GoodsListResponse);
  12. //创建商品
  13. rpc CreateGoods(CreateGoodsInfo) returns (GoodsInfoResponse);
  14. //删除商品
  15. rpc DeleteGoods(DeleteGoodsInfo) returns (google.protobuf.Empty);
  16. //修改商品
  17. rpc UpdateGoods(CreateGoodsInfo) returns (google.protobuf.Empty);
  18. //商品详情
  19. rpc GetGoodsDetail(GoodInfoRequest) returns(GoodsInfoResponse);
  20. //商品分类
  21. //获取所有的分类
  22. rpc GetAllCategoryList(google.protobuf.Empty) returns(CategoryListResponse);
  23. //新建分类信息
  24. rpc CreateCategory(CategoryInfoRequest) returns(CategoryInfoResponse);
  25. //删除分类
  26. rpc DeleteCategory(DeleteCategoryRequest) returns(google.protobuf.Empty);
  27. //修改分类信息
  28. rpc UpdateCategory(CategoryInfoRequest) returns(google.protobuf.Empty);
  29. //品牌
  30. //品牌列表信息
  31. rpc BrandList(BrandFilterRequest) returns(BrandListResponse);
  32. //新建品牌信息
  33. rpc CreateBrand(BrandRequest) returns(BrandInfoResponse);
  34. //删除品牌
  35. rpc DeleteBrand(BrandRequest) returns(google.protobuf.Empty);
  36. //修改品牌信息
  37. rpc UpdateBrand(BrandRequest) returns(google.protobuf.Empty);
  38. //轮播图
  39. //获取轮播列表信息
  40. rpc BannerList(google.protobuf.Empty) returns(BannerListResponse);
  41. //添加banner图
  42. rpc CreateBanner(BannerRequest) returns(BannerResponse);
  43. //删除轮播图
  44. rpc DeleteBanner(BannerRequest) returns(google.protobuf.Empty);
  45. //修改轮播图
  46. rpc UpdateBanner(BannerRequest) returns(google.protobuf.Empty);
  47. //品牌分类
  48. //获取品牌分类列表
  49. rpc CategoryBrandList(CategoryBrandFilterRequest) returns(CategoryBrandListResponse);
  50. //通过category获取brands
  51. rpc GetCategoryBrandList(CategoryInfoRequest) returns(BrandListResponse);
  52. //通过brands获取categories
  53. //添加分类品牌
  54. rpc CreateCategoryBrand(CategoryBrandRequest) returns(CategoryBrandResponse);
  55. //删除轮播图
  56. rpc DeleteCategoryBrand(CategoryBrandRequest) returns(google.protobuf.Empty);
  57. //修改轮播图
  58. rpc UpdateCategoryBrand(CategoryBrandRequest) returns(google.protobuf.Empty);
  59. }
  60. //商品列表请求消息体
  61. message GoodsFilterRequest {
  62. int32 priceMin = 1;//最小价格
  63. int32 priceMax = 2; //最大价格
  64. int32 isHot = 3; //是否是热门
  65. int32 isNew = 4; //是否是新品
  66. int32 isTab = 5; //是否是分类选项
  67. int32 topCategory = 6; //是否是顶级分类
  68. int32 pages = 7; //页码
  69. int32 pagePerNums = 8; //每页现实条数
  70. string keyWords = 9; //关键字
  71. int32 brand = 10;//品牌
  72. }
  73. //商品列表的返回消息题
  74. message GoodsListResponse {
  75. int32 total = 1; //总条数
  76. repeated GoodsInfoResponse data = 2; //每个商品信息
  77. }
  78. //商品信息
  79. message GoodsInfoResponse {
  80. int32 id = 1;
  81. int32 categoryId = 2;
  82. string name = 3;
  83. string goodsSn = 4;
  84. int32 clickNum = 5;
  85. int32 soldNum = 6;
  86. int32 favNum = 7;
  87. float marketPrice = 9;
  88. float shopPrice = 10;
  89. string goodsBrief = 11;
  90. string goodsDesc = 12;
  91. int32 shipFree = 13;
  92. repeated string images = 14;
  93. repeated string descImages = 15;
  94. string goodsFrontImage = 16;
  95. int32 isNew = 17;
  96. int32 isHot = 18;
  97. int32 onSale = 19;
  98. int64 addTime = 20;
  99. CategoryBriefInfoResponse category = 21;
  100. BrandInfoResponse brand = 22;
  101. }
  102. //分类信息结构体
  103. message CategoryBriefInfoResponse {
  104. int32 id = 1;
  105. string name = 2;
  106. }
  107. //品牌信息结构体
  108. message BrandInfoResponse {
  109. int32 id = 1;
  110. string name = 2;
  111. string logo = 3;
  112. }
  113. //多件商品的id
  114. message BatchGoodsIdInfo {
  115. repeated int32 id = 1;
  116. }
  117. //创建商品的消息体
  118. message CreateGoodsInfo {
  119. int32 id = 1;
  120. string name = 2;
  121. string goodsSn = 3;
  122. int32 stocks = 7; //库存,
  123. float marketPrice = 8;
  124. float shopPrice = 9;
  125. string goodsBrief = 10;
  126. string goodsDesc = 11;
  127. int32 shipFree = 12;
  128. repeated string images = 13;
  129. repeated string descImages = 14;
  130. string goodsFrontImage = 15;
  131. int32 isNew = 16;
  132. int32 isHot = 17;
  133. int32 onSale = 18;
  134. int32 categoryId = 19;
  135. int32 brandId = 20;
  136. }
  137. //删除商品id
  138. message DeleteGoodsInfo {
  139. int32 id = 1;
  140. }
  141. //商品详情
  142. message GoodInfoRequest {
  143. int32 id = 1;
  144. }
  145. //分类列表响应
  146. message CategoryListResponse {
  147. int32 total = 1;
  148. repeated CategoryInfoResponse data = 2;
  149. string jsonData = 3;
  150. }
  151. //单个分类数据
  152. message CategoryInfoResponse {
  153. int32 id = 1;
  154. string name = 2;
  155. int32 parentCategory = 3;
  156. int32 level = 4;
  157. bool isTab = 5;
  158. }
  159. message CategoryInfoRequest {
  160. int32 id = 1;
  161. string name = 2;
  162. int32 parentCategory = 3;
  163. int32 level = 4;
  164. bool isTab = 5;
  165. }
  166. message DeleteCategoryRequest {
  167. int32 id = 1;
  168. }
  169. message BrandFilterRequest {
  170. int32 pages = 1;
  171. int32 pagePerNums = 2;
  172. }
  173. message BrandListResponse {
  174. int32 total = 1;
  175. repeated BrandInfoResponse data = 2;
  176. }
  177. message BrandRequest {
  178. int32 id = 1;
  179. string name = 2;
  180. string logo = 3;
  181. }
  182. message BannerListResponse {
  183. int32 total = 1;
  184. repeated BannerResponse data = 2;
  185. }
  186. message BannerResponse {
  187. int32 id = 1;
  188. int32 index = 2;
  189. string image = 3;
  190. string url = 4;
  191. }
  192. message BannerRequest {
  193. int32 id = 1;
  194. int32 index = 2;
  195. string image = 3;
  196. string url = 4;
  197. }
  198. message CategoryBrandFilterRequest {
  199. int32 pages = 1;
  200. int32 pagePerNums = 2;
  201. }
  202. message CategoryBrandListResponse {
  203. int32 total = 1;
  204. repeated CategoryBrandResponse data = 2;
  205. }
  206. message CategoryBrandResponse{
  207. int32 id = 1;
  208. BrandInfoResponse brand = 2;
  209. CategoryInfoResponse category = 3;
  210. }
  211. message CategoryBrandRequest{
  212. int32 id = 1;
  213. int32 categoryId = 2;
  214. int32 brandId = 3;
  215. }

proto生成

  1. protoc -I . goods.proto --go_out=plugins=grpc:.
  2. protoc --go_out=. --go_opt=paths=import --go-grpc_out=. --go-grpc_opt=paths=import *.proto