zoukankan      html  css  js  c++  java
  • 导入外部proto获取商品信息

    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文件可以直接返回其中定义的结构体模型
    }




  • 相关阅读:
    常用辅助类(ContDownLatch、CyclicBarrier、Semaphore)
    Redis
    SpringBoot
    微服务概述
    数据库 子查询和分页查询
    数据库基础语句,聚合函数,练习
    数据库基础知识

    for循环的类型以及while循环
    C#编程循环练习
  • 原文地址:https://www.cnblogs.com/hualou/p/12070529.html
Copyright © 2011-2022 走看看