我正在学习 Go 中的 protobuf 和 gRPC。在生成 pb.go 文件时
protoc --go_out=plugins=grpc:chat chat.proto
对于文件chat.proto
syntax = "proto3";
package chat;
message Message {
string body = 1;
}
service ChatService {
rpc SayHello(Message) returns (Message) {}
}
生成的chat.pb.go有这两个接口:
type ChatServiceClient interface {
SayHello(ctx context.Context, in *Message, opts ...grpc.CallOption) (*Message, error)
}
...
type ChatServiceServer interface {
SayHello(context.Context, *Message) (*Message, error)
}
ChatServiceClient我对在界面中使用命名参数感到困惑。有没有使用这些参数ctx:in和opts。在这种情况下,我们什么时候应该命名参数和未命名参数?
饮歌长啸
相关分类