Documentation
¶
Index ¶
- Constants
- Variables
- func RegisterUserServiceServer(s grpc.ServiceRegistrar, srv UserServiceServer)
- type Address
- type Gender
- type GetByIdRequest
- type GetByIdResponse
- type Service
- type UnimplementedUserServiceServer
- type UnsafeUserServiceServer
- type User
- func (*User) Descriptor() ([]byte, []int)deprecated
- func (x *User) GetAddress() *Address
- func (x *User) GetAge() int32
- func (x *User) GetAttributes() map[string]string
- func (x *User) GetAvatar() string
- func (x *User) GetContacts() isUser_Contacts
- func (x *User) GetEmail() string
- func (x *User) GetGender() Gender
- func (x *User) GetId() int64
- func (x *User) GetName() string
- func (x *User) GetNicknames() []string
- func (x *User) GetPhone() string
- func (*User) ProtoMessage()
- func (x *User) ProtoReflect() protoreflect.Message
- func (x *User) Reset()
- func (x *User) String() string
- type UserServiceClient
- type UserServiceServer
- type User_Email
- type User_Phone
Constants ¶
const ( UserService_GetById_FullMethodName = "/UserService/GetById" UserService_GetById1_FullMethodName = "/UserService/GetById1" )
Variables ¶
var ( Gender_name = map[int32]string{ 0: "GENDER_UNKNOWN", 1: "GENDER_MALE", 2: "GENDER_FEMALE", } Gender_value = map[string]int32{ "GENDER_UNKNOWN": 0, "GENDER_MALE": 1, "GENDER_FEMALE": 2, } )
Enum value maps for Gender.
var File_user_proto protoreflect.FileDescriptor
var UserService_ServiceDesc = grpc.ServiceDesc{ ServiceName: "UserService", HandlerType: (*UserServiceServer)(nil), Methods: []grpc.MethodDesc{ { MethodName: "GetById", Handler: _UserService_GetById_Handler, }, { MethodName: "GetById1", Handler: _UserService_GetById1_Handler, }, }, Streams: []grpc.StreamDesc{}, Metadata: "user.proto", }
UserService_ServiceDesc is the grpc.ServiceDesc for UserService service. It's only intended for direct use with grpc.RegisterService, and not to be introspected or modified (even as a copy)
Functions ¶
func RegisterUserServiceServer ¶
func RegisterUserServiceServer(s grpc.ServiceRegistrar, srv UserServiceServer)
Types ¶
type Address ¶
type Address struct {
Province string `protobuf:"bytes,1,opt,name=province,proto3" json:"province,omitempty"`
City string `protobuf:"bytes,2,opt,name=city,proto3" json:"city,omitempty"`
// contains filtered or unexported fields
}
匿名嵌套结构
func (*Address) ProtoReflect ¶
func (x *Address) ProtoReflect() protoreflect.Message
type Gender ¶
type Gender int32
枚举类型
func (Gender) Descriptor ¶
func (Gender) Descriptor() protoreflect.EnumDescriptor
func (Gender) Number ¶
func (x Gender) Number() protoreflect.EnumNumber
func (Gender) Type ¶
func (Gender) Type() protoreflect.EnumType
type GetByIdRequest ¶
type GetByIdRequest struct {
Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"`
// contains filtered or unexported fields
}
定义输入
func (*GetByIdRequest) Descriptor
deprecated
func (*GetByIdRequest) Descriptor() ([]byte, []int)
Deprecated: Use GetByIdRequest.ProtoReflect.Descriptor instead.
func (*GetByIdRequest) GetId ¶
func (x *GetByIdRequest) GetId() int64
func (*GetByIdRequest) ProtoMessage ¶
func (*GetByIdRequest) ProtoMessage()
func (*GetByIdRequest) ProtoReflect ¶
func (x *GetByIdRequest) ProtoReflect() protoreflect.Message
func (*GetByIdRequest) Reset ¶
func (x *GetByIdRequest) Reset()
func (*GetByIdRequest) String ¶
func (x *GetByIdRequest) String() string
type GetByIdResponse ¶
type GetByIdResponse struct {
User *User `protobuf:"bytes,1,opt,name=user,proto3" json:"user,omitempty"`
// contains filtered or unexported fields
}
定义输出
func (*GetByIdResponse) Descriptor
deprecated
func (*GetByIdResponse) Descriptor() ([]byte, []int)
Deprecated: Use GetByIdResponse.ProtoReflect.Descriptor instead.
func (*GetByIdResponse) GetUser ¶
func (x *GetByIdResponse) GetUser() *User
func (*GetByIdResponse) ProtoMessage ¶
func (*GetByIdResponse) ProtoMessage()
func (*GetByIdResponse) ProtoReflect ¶
func (x *GetByIdResponse) ProtoReflect() protoreflect.Message
func (*GetByIdResponse) Reset ¶
func (x *GetByIdResponse) Reset()
func (*GetByIdResponse) String ¶
func (x *GetByIdResponse) String() string
type Service ¶
type Service struct {
UnimplementedUserServiceServer // 继承,实现service的时候【必须强制组合mented】,也是为了向后兼容
Name string
}
Service 实现 service
func (*Service) GetById ¶
func (s *Service) GetById(ctx context.Context, request *GetByIdRequest) (*GetByIdResponse, error)
func (*Service) GetById1 ¶
func (s *Service) GetById1(ctx context.Context, request *GetByIdRequest) (*GetByIdResponse, error)
type UnimplementedUserServiceServer ¶
type UnimplementedUserServiceServer struct{}
UnimplementedUserServiceServer must be embedded to have forward compatible implementations.
NOTE: this should be embedded by value instead of pointer to avoid a nil pointer dereference when methods are called.
func (UnimplementedUserServiceServer) GetById ¶
func (UnimplementedUserServiceServer) GetById(context.Context, *GetByIdRequest) (*GetByIdResponse, error)
func (UnimplementedUserServiceServer) GetById1 ¶
func (UnimplementedUserServiceServer) GetById1(context.Context, *GetByIdRequest) (*GetByIdResponse, error)
type UnsafeUserServiceServer ¶
type UnsafeUserServiceServer interface {
// contains filtered or unexported methods
}
UnsafeUserServiceServer may be embedded to opt out of forward compatibility for this service. Use of this interface is not recommended, as added methods to UserServiceServer will result in compilation errors.
type User ¶
type User struct {
Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"`
Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"`
// 编号可以不连续【即便删除字段,也不要复用被删除的编号】
Avatar string `protobuf:"bytes,4,opt,name=avatar,proto3" json:"avatar,omitempty"`
// protobuf 也是支持map结构和的
Attributes map[string]string `` // map<key,value>
/* 147-byte string literal not displayed */
Nicknames []string `protobuf:"bytes,6,rep,name=nicknames,proto3" json:"nicknames,omitempty"` // repeated表示数组
Age *int32 `protobuf:"varint,7,opt,name=age,proto3,oneof" json:"age,omitempty"` // optional表示可选字段
Address *Address `protobuf:"bytes,8,opt,name=address,proto3" json:"address,omitempty"` // 匿名嵌套结构
// Types that are valid to be assigned to Contacts:
//
// *User_Email
// *User_Phone
Contacts isUser_Contacts `protobuf_oneof:"contacts"`
Gender Gender `protobuf:"varint,11,opt,name=gender,proto3,enum=Gender" json:"gender,omitempty"` // 枚举类型
// contains filtered or unexported fields
}
定义一个消息体【1、2、3、是编号,编号只能从1开始】
func (*User) ProtoReflect ¶
func (x *User) ProtoReflect() protoreflect.Message
type UserServiceClient ¶
type UserServiceClient interface {
GetById(ctx context.Context, in *GetByIdRequest, opts ...grpc.CallOption) (*GetByIdResponse, error)
GetById1(ctx context.Context, in *GetByIdRequest, opts ...grpc.CallOption) (*GetByIdResponse, error)
}
UserServiceClient is the client API for UserService service.
For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
定义一个服务接口、service
func NewUserServiceClient ¶
func NewUserServiceClient(cc grpc.ClientConnInterface) UserServiceClient
type UserServiceServer ¶
type UserServiceServer interface {
GetById(context.Context, *GetByIdRequest) (*GetByIdResponse, error)
GetById1(context.Context, *GetByIdRequest) (*GetByIdResponse, error)
// contains filtered or unexported methods
}
UserServiceServer is the server API for UserService service. All implementations must embed UnimplementedUserServiceServer for forward compatibility.
定义一个服务接口、service
Source Files
¶
- service.go
- user.pb.go
- user_grpc.pb.go