企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持知识库和私有化部署方案 广告
[TOC] ## 参数为空的grpc请求怎么定义 google protobuf已经提供了空参数 ``` //empty.proto message Empty {} ``` 使用方法,在proto文件中导入`empty.proto`, 定义一个请求参数和返回值为空的函数`emptyfunction`, 函数名字可以自定义。 ``` //server.proto import "google/protobuf/empty.proto"; service pbservice{ rpc emptyfunction(google.protobuf.Empty) return{google.protobuf.Empty} } ``` 以golang语言为例子,在go中对应的函数为: ``` func (s *service) emptyfunction(ctx context.Context, g *google_protobuf.Empty) (*google_protobuf.Empty, error) {} ``` 到此,空请求和空返回的grpc就完成了。