原来是这么做的,这样做,给GetById
传参都要把参数转为对象
message id {
string uid=1;
}
service xxx {
rpc GetById(id) returns(...){}
}
//编译后
type Id struct {
Uid string
}
type Xxx interface {
GetById(context.Context, *Id) (...)
}
能不能实现类似下面的方法(下面方法编译不通过的),也就是传参只传string
就行,不用传对象
service xxx {
rpc GetById(string) returns(...){}
}
//编译后
type Xxx interface {
GetById(context.Context, string) (...)
}
grpc 对外的方法只能传递 protobuf 的 Message 。而且传递过程是 grpc 自动完成的。