NIUCLOUD是一款SaaS管理后台框架多应用插件+云编译。上千名开发者、服务商正在积极拥抱开发者生态。欢迎开发者们免费入驻。一起助力发展! 广告
[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就完成了。