【grpc - go】如何写一个 gRPC 服务端

约定Server / ServiceServer 指服务端Service 指服务端提供的若干服务项项目结构---my_project |---protocol | |---hello_world | |---hello_world.pb.go | |---hello_world.proto | |---hello_world_grpc.pb.go |---service |---hello_worl
摘要由CSDN通过智能技术生成

约定

  • Server / Service
    • Server 指服务端
    • Service 指服务端提供的若干服务项

项目结构

---my_project
   |---protocol
   |   |---hello_world
   |       |---hello_world.pb.go
   |       |---hello_world.proto
   |       |---hello_world_grpc.pb.go
   |---service
       |---hello_world
           |---hello_world.go

具体操作

  1. protocol 目录下,一个 Service 一个文件夹,在这里 hello_world 就是一个 Service,Service 下写 .proto 文件
    package 后面需要跟 go_package 并指明文件在 git 上的路径,例如:
    option go_package = "github.com/xubk/my_project/protocol/hello_world";
  2. 进入 /protocol/${Service} 目录下,执行命令:
    protoc \
    -I=. \
    --go_out=. \
    --go_opt=paths=source_relative \
    --go-grpc_out=. \
    --go-grpc_opt=paths=source_relative \
    *.proto
    
  • 含义:
    • protoc 是
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值