feat 协议

This commit is contained in:
2026-01-09 14:08:41 +08:00
parent 69e82ec0fe
commit f381510a0d
5 changed files with 256 additions and 28 deletions

View File

@@ -24,6 +24,7 @@ const _ = grpc.SupportPackageIsVersion7
type UserClient interface {
Login(ctx context.Context, in *LoginReq, opts ...grpc.CallOption) (*LoginResp, error)
GetUserInfo(ctx context.Context, in *GetUserInfoReq, opts ...grpc.CallOption) (*GetUserInfoResp, error)
GenerateQuestion(ctx context.Context, in *GenerateQuestionReq, opts ...grpc.CallOption) (*GenerateQuestionResp, error)
}
type userClient struct {
@@ -52,12 +53,22 @@ func (c *userClient) GetUserInfo(ctx context.Context, in *GetUserInfoReq, opts .
return out, nil
}
func (c *userClient) GenerateQuestion(ctx context.Context, in *GenerateQuestionReq, opts ...grpc.CallOption) (*GenerateQuestionResp, error) {
out := new(GenerateQuestionResp)
err := c.cc.Invoke(ctx, "/User/GenerateQuestion", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
// UserServer is the server API for User service.
// All implementations must embed UnimplementedUserServer
// for forward compatibility
type UserServer interface {
Login(context.Context, *LoginReq) (*LoginResp, error)
GetUserInfo(context.Context, *GetUserInfoReq) (*GetUserInfoResp, error)
GenerateQuestion(context.Context, *GenerateQuestionReq) (*GenerateQuestionResp, error)
mustEmbedUnimplementedUserServer()
}
@@ -71,6 +82,9 @@ func (UnimplementedUserServer) Login(context.Context, *LoginReq) (*LoginResp, er
func (UnimplementedUserServer) GetUserInfo(context.Context, *GetUserInfoReq) (*GetUserInfoResp, error) {
return nil, status.Errorf(codes.Unimplemented, "method GetUserInfo not implemented")
}
func (UnimplementedUserServer) GenerateQuestion(context.Context, *GenerateQuestionReq) (*GenerateQuestionResp, error) {
return nil, status.Errorf(codes.Unimplemented, "method GenerateQuestion not implemented")
}
func (UnimplementedUserServer) mustEmbedUnimplementedUserServer() {}
// UnsafeUserServer may be embedded to opt out of forward compatibility for this service.
@@ -120,6 +134,24 @@ func _User_GetUserInfo_Handler(srv interface{}, ctx context.Context, dec func(in
return interceptor(ctx, in, info, handler)
}
func _User_GenerateQuestion_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(GenerateQuestionReq)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(UserServer).GenerateQuestion(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/User/GenerateQuestion",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(UserServer).GenerateQuestion(ctx, req.(*GenerateQuestionReq))
}
return interceptor(ctx, in, info, handler)
}
// User_ServiceDesc is the grpc.ServiceDesc for User service.
// It's only intended for direct use with grpc.RegisterService,
// and not to be introspected or modified (even as a copy)
@@ -135,6 +167,10 @@ var User_ServiceDesc = grpc.ServiceDesc{
MethodName: "GetUserInfo",
Handler: _User_GetUserInfo_Handler,
},
{
MethodName: "GenerateQuestion",
Handler: _User_GenerateQuestion_Handler,
},
},
Streams: []grpc.StreamDesc{},
Metadata: "service_user.proto",