1
All checks were successful
Auth & User Management Service CI / build-services (app/auth_service/Dockerfile, auth_service, auth_service) (push) Successful in 40s
Auth & User Management Service CI / build-services (app/douyin_ecpm_calculation_service/Dockerfile, douyin_ecpm_calculation_service, douyin_ecpm_calculation_service) (push) Successful in 36s
Auth & User Management Service CI / build-services (app/ranking_management/Dockerfile, ranking_management, ranking_management) (push) Successful in 42s
Auth & User Management Service CI / build-services (app/user_management/Dockerfile, user_manager, user_management) (push) Successful in 41s
Auth & User Management Service CI / start-services (push) Successful in 4s

This commit is contained in:
xiabin 2025-02-11 17:27:59 +08:00
parent d952782011
commit d1ebb98821
8 changed files with 253 additions and 44 deletions

View File

@ -6,6 +6,7 @@ import (
"gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/ranking_management/internal/logic/rankings" "gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/ranking_management/internal/logic/rankings"
"gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/ranking_management/internal/svc" "gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/ranking_management/internal/svc"
ranking_management2 "gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/ranking_management/ranking_management" ranking_management2 "gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/ranking_management/ranking_management"
"gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/user_management/user_management"
"gorm.io/gorm" "gorm.io/gorm"
"strconv" "strconv"
@ -43,7 +44,7 @@ func (l *GetRankingListLogic) GetRankingList(in *ranking_management2.GetRankingL
continue continue
} }
//查询用户数据FindOne带缓存 //查询用户数据FindOne带缓存
user, err := l.svcCtx.Query.AppUser.Where(l.svcCtx.Query.AppUser.ID.Eq(uint64(userId))).Take() user, err := l.svcCtx.UserManagerClient.GetUserById(l.ctx, &user_management.UserId{UserId: uint64(userId)})
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -4,9 +4,15 @@ import (
"context" "context"
"gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/ranking_management/internal/gen/dao/query" "gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/ranking_management/internal/gen/dao/query"
"gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/ranking_management/internal/logic/rankings" "gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/ranking_management/internal/logic/rankings"
"gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/user_management/user_management"
"gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/user_management/user_management_client"
"gitea.youtukeji.com.cn/xiabin/youtu_grpc/pkg/config" "gitea.youtukeji.com.cn/xiabin/youtu_grpc/pkg/config"
"gitea.youtukeji.com.cn/xiabin/youtu_grpc/pkg/my_gorm" "gitea.youtukeji.com.cn/xiabin/youtu_grpc/pkg/my_gorm"
"github.com/redis/go-redis/v9" "github.com/redis/go-redis/v9"
"github.com/spf13/viper"
"github.com/zeromicro/go-zero/core/conf"
"github.com/zeromicro/go-zero/core/discov"
"github.com/zeromicro/go-zero/zrpc"
"gorm.io/driver/mysql" "gorm.io/driver/mysql"
"gorm.io/gorm" "gorm.io/gorm"
) )
@ -15,6 +21,7 @@ type ServiceContext struct {
Config config.Config Config config.Config
Query *query.Query Query *query.Query
RedisRanking *rankings.Ranking RedisRanking *rankings.Ranking
UserManagerClient user_management_client.UserManagement
} }
func NewServiceContext(c config.Config) *ServiceContext { func NewServiceContext(c config.Config) *ServiceContext {
@ -34,6 +41,21 @@ func NewServiceContext(c config.Config) *ServiceContext {
svc.Query = query.Use(db) svc.Query = query.Use(db)
// 初始化用户客户端
clientConf := zrpc.RpcClientConf{}
err = conf.FillDefault(&clientConf) // 填充默认值,比如 trace 透传等,参考服务配置说明
if err != nil {
panic(err)
}
clientConf.Token = "user_management.rpc.key"
clientConf.App = "user_management.rpc"
clientConf.Etcd = discov.EtcdConf{ // 通过 etcd 服务发现
Hosts: []string{viper.GetString(config.EtcdAddrKey)},
Key: "user_management.rpc",
}
svc.UserManagerClient = user_management.NewUserManagementClient(zrpc.MustNewClient(clientConf).Conn())
//初始化排行榜对象 //初始化排行榜对象
svc.InitRankings(redisClient) svc.InitRankings(redisClient)

View File

@ -0,0 +1,44 @@
package logic
import (
"context"
"errors"
"gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/user_management/internal/svc"
"gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/user_management/user_management"
"github.com/zeromicro/go-zero/core/logx"
)
type GetUserByIdLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewGetUserByIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetUserByIdLogic {
return &GetUserByIdLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
// GetUserById 通过 ID 获取用户
func (l *GetUserByIdLogic) GetUserById(in *user_management.UserId) (*user_management.User, error) {
if in.GetUserId() == 0 {
return &user_management.User{}, errors.New("userId is empty")
}
user, err := l.svcCtx.Query.User.WithContext(l.ctx).Where(l.svcCtx.Query.User.ID.Eq(in.UserId)).First()
if err != nil {
return &user_management.User{}, err
}
return &user_management.User{
ID: user.ID,
Nickname: user.Nickname,
Avatar: user.Avatar,
}, nil
}

View File

@ -28,19 +28,26 @@ func (s *UserManagementServer) Ping(ctx context.Context, in *user_management.Req
return l.Ping(in) return l.Ping(in)
} }
// 设置用户信息 // SetUser 设置用户信息
func (s *UserManagementServer) SetUser(ctx context.Context, in *user_management.SetUserRequest) (*user_management.SetUserResponse, error) { func (s *UserManagementServer) SetUser(ctx context.Context, in *user_management.SetUserRequest) (*user_management.SetUserResponse, error) {
l := logic.NewSetUserLogic(ctx, s.svcCtx) l := logic.NewSetUserLogic(ctx, s.svcCtx)
return l.SetUser(in) return l.SetUser(in)
} }
// 获取用户或者创建用户 // CreateUser 获取用户或者创建用户
func (s *UserManagementServer) CreateUser(ctx context.Context, in *user_management.CreateUserRequest) (*user_management.UserId, error) { func (s *UserManagementServer) CreateUser(ctx context.Context, in *user_management.CreateUserRequest) (*user_management.UserId, error) {
l := logic.NewCreateUserLogic(ctx, s.svcCtx) l := logic.NewCreateUserLogic(ctx, s.svcCtx)
return l.CreateUser(in) return l.CreateUser(in)
} }
// CreateEmptyUser 创建空用户,用于关联游戏账号的空数据
func (s *UserManagementServer) CreateEmptyUser(ctx context.Context, in *user_management.Empty) (*user_management.UserId, error) { func (s *UserManagementServer) CreateEmptyUser(ctx context.Context, in *user_management.Empty) (*user_management.UserId, error) {
l := logic.NewCreateEmptyUserLogic(ctx, s.svcCtx) l := logic.NewCreateEmptyUserLogic(ctx, s.svcCtx)
return l.CreateEmptyUser(in) return l.CreateEmptyUser(in)
} }
// GetUserById 通过 ID 获取用户
func (s *UserManagementServer) GetUserById(ctx context.Context, in *user_management.UserId) (*user_management.User, error) {
l := logic.NewGetUserByIdLogic(ctx, s.svcCtx)
return l.GetUserById(in)
}

View File

@ -32,14 +32,24 @@ message UserId{
message Empty {}// message Empty {}//
message User {
uint64 ID = 1;
string Nickname = 2;
string Avatar = 3;
}
service user_management { service user_management {
rpc Ping(Request) returns(Response); rpc Ping(Request) returns(Response);
// //SetUser
rpc SetUser (SetUserRequest) returns(SetUserResponse); rpc SetUser (SetUserRequest) returns(SetUserResponse);
// //CreateUser
rpc CreateUser(CreateUserRequest) returns(UserId); rpc CreateUser(CreateUserRequest) returns(UserId);
//CreateEmptyUser ,
rpc CreateEmptyUser(Empty) returns(UserId); rpc CreateEmptyUser(Empty) returns(UserId);
//GetUserById ID
rpc GetUserById(UserId) returns(User);
} }

View File

@ -345,6 +345,66 @@ func (*Empty) Descriptor() ([]byte, []int) {
return file_user_management_proto_rawDescGZIP(), []int{6} return file_user_management_proto_rawDescGZIP(), []int{6}
} }
type User struct {
state protoimpl.MessageState `protogen:"open.v1"`
ID uint64 `protobuf:"varint,1,opt,name=ID,proto3" json:"ID,omitempty"`
Nickname string `protobuf:"bytes,2,opt,name=Nickname,proto3" json:"Nickname,omitempty"`
Avatar string `protobuf:"bytes,3,opt,name=Avatar,proto3" json:"Avatar,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *User) Reset() {
*x = User{}
mi := &file_user_management_proto_msgTypes[7]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *User) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*User) ProtoMessage() {}
func (x *User) ProtoReflect() protoreflect.Message {
mi := &file_user_management_proto_msgTypes[7]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use User.ProtoReflect.Descriptor instead.
func (*User) Descriptor() ([]byte, []int) {
return file_user_management_proto_rawDescGZIP(), []int{7}
}
func (x *User) GetID() uint64 {
if x != nil {
return x.ID
}
return 0
}
func (x *User) GetNickname() string {
if x != nil {
return x.Nickname
}
return ""
}
func (x *User) GetAvatar() string {
if x != nil {
return x.Avatar
}
return ""
}
var File_user_management_proto protoreflect.FileDescriptor var File_user_management_proto protoreflect.FileDescriptor
var file_user_management_proto_rawDesc = string([]byte{ var file_user_management_proto_rawDesc = string([]byte{
@ -371,27 +431,36 @@ var file_user_management_proto_rawDesc = string([]byte{
0x76, 0x61, 0x74, 0x61, 0x72, 0x22, 0x20, 0x0a, 0x06, 0x55, 0x73, 0x65, 0x72, 0x49, 0x64, 0x12, 0x76, 0x61, 0x74, 0x61, 0x72, 0x22, 0x20, 0x0a, 0x06, 0x55, 0x73, 0x65, 0x72, 0x49, 0x64, 0x12,
0x16, 0x0a, 0x06, 0x55, 0x73, 0x65, 0x72, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x04, 0x52, 0x16, 0x0a, 0x06, 0x55, 0x73, 0x65, 0x72, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x04, 0x52,
0x06, 0x55, 0x73, 0x65, 0x72, 0x49, 0x64, 0x22, 0x07, 0x0a, 0x05, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x06, 0x55, 0x73, 0x65, 0x72, 0x49, 0x64, 0x22, 0x07, 0x0a, 0x05, 0x45, 0x6d, 0x70, 0x74, 0x79,
0x32, 0xab, 0x02, 0x0a, 0x0f, 0x75, 0x73, 0x65, 0x72, 0x5f, 0x6d, 0x61, 0x6e, 0x61, 0x67, 0x65, 0x22, 0x4a, 0x0a, 0x04, 0x55, 0x73, 0x65, 0x72, 0x12, 0x0e, 0x0a, 0x02, 0x49, 0x44, 0x18, 0x01,
0x6d, 0x65, 0x6e, 0x74, 0x12, 0x3b, 0x0a, 0x04, 0x50, 0x69, 0x6e, 0x67, 0x12, 0x18, 0x2e, 0x75, 0x20, 0x01, 0x28, 0x04, 0x52, 0x02, 0x49, 0x44, 0x12, 0x1a, 0x0a, 0x08, 0x4e, 0x69, 0x63, 0x6b,
0x73, 0x65, 0x72, 0x5f, 0x6d, 0x61, 0x6e, 0x61, 0x67, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x2e, 0x52, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x4e, 0x69, 0x63, 0x6b,
0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x19, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x5f, 0x6d, 0x61, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x41, 0x76, 0x61, 0x74, 0x61, 0x72, 0x18, 0x03,
0x6e, 0x61, 0x67, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x2e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x41, 0x76, 0x61, 0x74, 0x61, 0x72, 0x32, 0xea, 0x02, 0x0a,
0x65, 0x12, 0x4c, 0x0a, 0x07, 0x53, 0x65, 0x74, 0x55, 0x73, 0x65, 0x72, 0x12, 0x1f, 0x2e, 0x75, 0x0f, 0x75, 0x73, 0x65, 0x72, 0x5f, 0x6d, 0x61, 0x6e, 0x61, 0x67, 0x65, 0x6d, 0x65, 0x6e, 0x74,
0x73, 0x65, 0x72, 0x5f, 0x6d, 0x61, 0x6e, 0x61, 0x67, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x2e, 0x53, 0x12, 0x3b, 0x0a, 0x04, 0x50, 0x69, 0x6e, 0x67, 0x12, 0x18, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x5f,
0x65, 0x74, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x20, 0x2e, 0x6d, 0x61, 0x6e, 0x61, 0x67, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x2e, 0x52, 0x65, 0x71, 0x75, 0x65,
0x73, 0x74, 0x1a, 0x19, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x5f, 0x6d, 0x61, 0x6e, 0x61, 0x67, 0x65,
0x6d, 0x65, 0x6e, 0x74, 0x2e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x4c, 0x0a,
0x07, 0x53, 0x65, 0x74, 0x55, 0x73, 0x65, 0x72, 0x12, 0x1f, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x5f,
0x6d, 0x61, 0x6e, 0x61, 0x67, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x2e, 0x53, 0x65, 0x74, 0x55, 0x73,
0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x20, 0x2e, 0x75, 0x73, 0x65, 0x72,
0x5f, 0x6d, 0x61, 0x6e, 0x61, 0x67, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x2e, 0x53, 0x65, 0x74, 0x55,
0x73, 0x65, 0x72, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x49, 0x0a, 0x0a, 0x43,
0x72, 0x65, 0x61, 0x74, 0x65, 0x55, 0x73, 0x65, 0x72, 0x12, 0x22, 0x2e, 0x75, 0x73, 0x65, 0x72,
0x5f, 0x6d, 0x61, 0x6e, 0x61, 0x67, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x2e, 0x43, 0x72, 0x65, 0x61,
0x74, 0x65, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x17, 0x2e,
0x75, 0x73, 0x65, 0x72, 0x5f, 0x6d, 0x61, 0x6e, 0x61, 0x67, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x5f, 0x6d, 0x61, 0x6e, 0x61, 0x67, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x2e,
0x53, 0x65, 0x74, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x55, 0x73, 0x65, 0x72, 0x49, 0x64, 0x12, 0x42, 0x0a, 0x0f, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65,
0x49, 0x0a, 0x0a, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x55, 0x73, 0x65, 0x72, 0x12, 0x22, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x55, 0x73, 0x65, 0x72, 0x12, 0x16, 0x2e, 0x75, 0x73, 0x65, 0x72,
0x75, 0x73, 0x65, 0x72, 0x5f, 0x6d, 0x61, 0x6e, 0x61, 0x67, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x2e, 0x5f, 0x6d, 0x61, 0x6e, 0x61, 0x67, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x2e, 0x45, 0x6d, 0x70, 0x74,
0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x79, 0x1a, 0x17, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x5f, 0x6d, 0x61, 0x6e, 0x61, 0x67, 0x65, 0x6d,
0x74, 0x1a, 0x17, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x5f, 0x6d, 0x61, 0x6e, 0x61, 0x67, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x2e, 0x55, 0x73, 0x65, 0x72, 0x49, 0x64, 0x12, 0x3d, 0x0a, 0x0b, 0x47, 0x65,
0x65, 0x6e, 0x74, 0x2e, 0x55, 0x73, 0x65, 0x72, 0x49, 0x64, 0x12, 0x42, 0x0a, 0x0f, 0x43, 0x72, 0x74, 0x55, 0x73, 0x65, 0x72, 0x42, 0x79, 0x49, 0x64, 0x12, 0x17, 0x2e, 0x75, 0x73, 0x65, 0x72,
0x65, 0x61, 0x74, 0x65, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x55, 0x73, 0x65, 0x72, 0x12, 0x16, 0x2e, 0x5f, 0x6d, 0x61, 0x6e, 0x61, 0x67, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x2e, 0x55, 0x73, 0x65, 0x72,
0x75, 0x73, 0x65, 0x72, 0x5f, 0x6d, 0x61, 0x6e, 0x61, 0x67, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x2e, 0x49, 0x64, 0x1a, 0x15, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x5f, 0x6d, 0x61, 0x6e, 0x61, 0x67, 0x65,
0x45, 0x6d, 0x70, 0x74, 0x79, 0x1a, 0x17, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x5f, 0x6d, 0x61, 0x6e, 0x6d, 0x65, 0x6e, 0x74, 0x2e, 0x55, 0x73, 0x65, 0x72, 0x42, 0x13, 0x5a, 0x11, 0x2e, 0x2f, 0x75,
0x61, 0x67, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x2e, 0x55, 0x73, 0x65, 0x72, 0x49, 0x64, 0x42, 0x13, 0x73, 0x65, 0x72, 0x5f, 0x6d, 0x61, 0x6e, 0x61, 0x67, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x62, 0x06,
0x5a, 0x11, 0x2e, 0x2f, 0x75, 0x73, 0x65, 0x72, 0x5f, 0x6d, 0x61, 0x6e, 0x61, 0x67, 0x65, 0x6d, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
0x65, 0x6e, 0x74, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
}) })
var ( var (
@ -406,7 +475,7 @@ func file_user_management_proto_rawDescGZIP() []byte {
return file_user_management_proto_rawDescData return file_user_management_proto_rawDescData
} }
var file_user_management_proto_msgTypes = make([]protoimpl.MessageInfo, 7) var file_user_management_proto_msgTypes = make([]protoimpl.MessageInfo, 8)
var file_user_management_proto_goTypes = []any{ var file_user_management_proto_goTypes = []any{
(*Request)(nil), // 0: user_management.Request (*Request)(nil), // 0: user_management.Request
(*Response)(nil), // 1: user_management.Response (*Response)(nil), // 1: user_management.Response
@ -415,18 +484,21 @@ var file_user_management_proto_goTypes = []any{
(*CreateUserRequest)(nil), // 4: user_management.CreateUserRequest (*CreateUserRequest)(nil), // 4: user_management.CreateUserRequest
(*UserId)(nil), // 5: user_management.UserId (*UserId)(nil), // 5: user_management.UserId
(*Empty)(nil), // 6: user_management.Empty (*Empty)(nil), // 6: user_management.Empty
(*User)(nil), // 7: user_management.User
} }
var file_user_management_proto_depIdxs = []int32{ var file_user_management_proto_depIdxs = []int32{
0, // 0: user_management.user_management.Ping:input_type -> user_management.Request 0, // 0: user_management.user_management.Ping:input_type -> user_management.Request
2, // 1: user_management.user_management.SetUser:input_type -> user_management.SetUserRequest 2, // 1: user_management.user_management.SetUser:input_type -> user_management.SetUserRequest
4, // 2: user_management.user_management.CreateUser:input_type -> user_management.CreateUserRequest 4, // 2: user_management.user_management.CreateUser:input_type -> user_management.CreateUserRequest
6, // 3: user_management.user_management.CreateEmptyUser:input_type -> user_management.Empty 6, // 3: user_management.user_management.CreateEmptyUser:input_type -> user_management.Empty
1, // 4: user_management.user_management.Ping:output_type -> user_management.Response 5, // 4: user_management.user_management.GetUserById:input_type -> user_management.UserId
3, // 5: user_management.user_management.SetUser:output_type -> user_management.SetUserResponse 1, // 5: user_management.user_management.Ping:output_type -> user_management.Response
5, // 6: user_management.user_management.CreateUser:output_type -> user_management.UserId 3, // 6: user_management.user_management.SetUser:output_type -> user_management.SetUserResponse
5, // 7: user_management.user_management.CreateEmptyUser:output_type -> user_management.UserId 5, // 7: user_management.user_management.CreateUser:output_type -> user_management.UserId
4, // [4:8] is the sub-list for method output_type 5, // 8: user_management.user_management.CreateEmptyUser:output_type -> user_management.UserId
0, // [0:4] is the sub-list for method input_type 7, // 9: user_management.user_management.GetUserById:output_type -> user_management.User
5, // [5:10] is the sub-list for method output_type
0, // [0:5] is the sub-list for method input_type
0, // [0:0] is the sub-list for extension type_name 0, // [0:0] is the sub-list for extension type_name
0, // [0:0] is the sub-list for extension extendee 0, // [0:0] is the sub-list for extension extendee
0, // [0:0] is the sub-list for field type_name 0, // [0:0] is the sub-list for field type_name
@ -443,7 +515,7 @@ func file_user_management_proto_init() {
GoPackagePath: reflect.TypeOf(x{}).PkgPath(), GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: unsafe.Slice(unsafe.StringData(file_user_management_proto_rawDesc), len(file_user_management_proto_rawDesc)), RawDescriptor: unsafe.Slice(unsafe.StringData(file_user_management_proto_rawDesc), len(file_user_management_proto_rawDesc)),
NumEnums: 0, NumEnums: 0,
NumMessages: 7, NumMessages: 8,
NumExtensions: 0, NumExtensions: 0,
NumServices: 1, NumServices: 1,
}, },

View File

@ -23,6 +23,7 @@ const (
UserManagement_SetUser_FullMethodName = "/user_management.user_management/SetUser" UserManagement_SetUser_FullMethodName = "/user_management.user_management/SetUser"
UserManagement_CreateUser_FullMethodName = "/user_management.user_management/CreateUser" UserManagement_CreateUser_FullMethodName = "/user_management.user_management/CreateUser"
UserManagement_CreateEmptyUser_FullMethodName = "/user_management.user_management/CreateEmptyUser" UserManagement_CreateEmptyUser_FullMethodName = "/user_management.user_management/CreateEmptyUser"
UserManagement_GetUserById_FullMethodName = "/user_management.user_management/GetUserById"
) )
// UserManagementClient is the client API for UserManagement service. // UserManagementClient is the client API for UserManagement service.
@ -30,11 +31,14 @@ const (
// 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. // 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.
type UserManagementClient interface { type UserManagementClient interface {
Ping(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Response, error) Ping(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Response, error)
// 设置用户信息 // SetUser 设置用户信息
SetUser(ctx context.Context, in *SetUserRequest, opts ...grpc.CallOption) (*SetUserResponse, error) SetUser(ctx context.Context, in *SetUserRequest, opts ...grpc.CallOption) (*SetUserResponse, error)
// 获取用户或者创建用户 // CreateUser 获取用户或者创建用户
CreateUser(ctx context.Context, in *CreateUserRequest, opts ...grpc.CallOption) (*UserId, error) CreateUser(ctx context.Context, in *CreateUserRequest, opts ...grpc.CallOption) (*UserId, error)
// CreateEmptyUser 创建空用户,用于关联游戏账号的空数据
CreateEmptyUser(ctx context.Context, in *Empty, opts ...grpc.CallOption) (*UserId, error) CreateEmptyUser(ctx context.Context, in *Empty, opts ...grpc.CallOption) (*UserId, error)
// GetUserById 通过 ID 获取用户
GetUserById(ctx context.Context, in *UserId, opts ...grpc.CallOption) (*User, error)
} }
type userManagementClient struct { type userManagementClient struct {
@ -85,16 +89,29 @@ func (c *userManagementClient) CreateEmptyUser(ctx context.Context, in *Empty, o
return out, nil return out, nil
} }
func (c *userManagementClient) GetUserById(ctx context.Context, in *UserId, opts ...grpc.CallOption) (*User, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(User)
err := c.cc.Invoke(ctx, UserManagement_GetUserById_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
// UserManagementServer is the server API for UserManagement service. // UserManagementServer is the server API for UserManagement service.
// All implementations must embed UnimplementedUserManagementServer // All implementations must embed UnimplementedUserManagementServer
// for forward compatibility. // for forward compatibility.
type UserManagementServer interface { type UserManagementServer interface {
Ping(context.Context, *Request) (*Response, error) Ping(context.Context, *Request) (*Response, error)
// 设置用户信息 // SetUser 设置用户信息
SetUser(context.Context, *SetUserRequest) (*SetUserResponse, error) SetUser(context.Context, *SetUserRequest) (*SetUserResponse, error)
// 获取用户或者创建用户 // CreateUser 获取用户或者创建用户
CreateUser(context.Context, *CreateUserRequest) (*UserId, error) CreateUser(context.Context, *CreateUserRequest) (*UserId, error)
// CreateEmptyUser 创建空用户,用于关联游戏账号的空数据
CreateEmptyUser(context.Context, *Empty) (*UserId, error) CreateEmptyUser(context.Context, *Empty) (*UserId, error)
// GetUserById 通过 ID 获取用户
GetUserById(context.Context, *UserId) (*User, error)
mustEmbedUnimplementedUserManagementServer() mustEmbedUnimplementedUserManagementServer()
} }
@ -117,6 +134,9 @@ func (UnimplementedUserManagementServer) CreateUser(context.Context, *CreateUser
func (UnimplementedUserManagementServer) CreateEmptyUser(context.Context, *Empty) (*UserId, error) { func (UnimplementedUserManagementServer) CreateEmptyUser(context.Context, *Empty) (*UserId, error) {
return nil, status.Errorf(codes.Unimplemented, "method CreateEmptyUser not implemented") return nil, status.Errorf(codes.Unimplemented, "method CreateEmptyUser not implemented")
} }
func (UnimplementedUserManagementServer) GetUserById(context.Context, *UserId) (*User, error) {
return nil, status.Errorf(codes.Unimplemented, "method GetUserById not implemented")
}
func (UnimplementedUserManagementServer) mustEmbedUnimplementedUserManagementServer() {} func (UnimplementedUserManagementServer) mustEmbedUnimplementedUserManagementServer() {}
func (UnimplementedUserManagementServer) testEmbeddedByValue() {} func (UnimplementedUserManagementServer) testEmbeddedByValue() {}
@ -210,6 +230,24 @@ func _UserManagement_CreateEmptyUser_Handler(srv interface{}, ctx context.Contex
return interceptor(ctx, in, info, handler) return interceptor(ctx, in, info, handler)
} }
func _UserManagement_GetUserById_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(UserId)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(UserManagementServer).GetUserById(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: UserManagement_GetUserById_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(UserManagementServer).GetUserById(ctx, req.(*UserId))
}
return interceptor(ctx, in, info, handler)
}
// UserManagement_ServiceDesc is the grpc.ServiceDesc for UserManagement service. // UserManagement_ServiceDesc is the grpc.ServiceDesc for UserManagement service.
// It's only intended for direct use with grpc.RegisterService, // It's only intended for direct use with grpc.RegisterService,
// and not to be introspected or modified (even as a copy) // and not to be introspected or modified (even as a copy)
@ -233,6 +271,10 @@ var UserManagement_ServiceDesc = grpc.ServiceDesc{
MethodName: "CreateEmptyUser", MethodName: "CreateEmptyUser",
Handler: _UserManagement_CreateEmptyUser_Handler, Handler: _UserManagement_CreateEmptyUser_Handler,
}, },
{
MethodName: "GetUserById",
Handler: _UserManagement_GetUserById_Handler,
},
}, },
Streams: []grpc.StreamDesc{}, Streams: []grpc.StreamDesc{},
Metadata: "user_management.proto", Metadata: "user_management.proto",

View File

@ -20,15 +20,19 @@ type (
Response = user_management.Response Response = user_management.Response
SetUserRequest = user_management.SetUserRequest SetUserRequest = user_management.SetUserRequest
SetUserResponse = user_management.SetUserResponse SetUserResponse = user_management.SetUserResponse
User = user_management.User
UserId = user_management.UserId UserId = user_management.UserId
UserManagement interface { UserManagement interface {
Ping(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Response, error) Ping(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Response, error)
// 设置用户信息 // SetUser 设置用户信息
SetUser(ctx context.Context, in *SetUserRequest, opts ...grpc.CallOption) (*SetUserResponse, error) SetUser(ctx context.Context, in *SetUserRequest, opts ...grpc.CallOption) (*SetUserResponse, error)
// 获取用户或者创建用户 // CreateUser 获取用户或者创建用户
CreateUser(ctx context.Context, in *CreateUserRequest, opts ...grpc.CallOption) (*UserId, error) CreateUser(ctx context.Context, in *CreateUserRequest, opts ...grpc.CallOption) (*UserId, error)
// CreateEmptyUser 创建空用户,用于关联游戏账号的空数据
CreateEmptyUser(ctx context.Context, in *Empty, opts ...grpc.CallOption) (*UserId, error) CreateEmptyUser(ctx context.Context, in *Empty, opts ...grpc.CallOption) (*UserId, error)
// GetUserById 通过 ID 获取用户
GetUserById(ctx context.Context, in *UserId, opts ...grpc.CallOption) (*User, error)
} }
defaultUserManagement struct { defaultUserManagement struct {
@ -47,19 +51,26 @@ func (m *defaultUserManagement) Ping(ctx context.Context, in *Request, opts ...g
return client.Ping(ctx, in, opts...) return client.Ping(ctx, in, opts...)
} }
// 设置用户信息 // SetUser 设置用户信息
func (m *defaultUserManagement) SetUser(ctx context.Context, in *SetUserRequest, opts ...grpc.CallOption) (*SetUserResponse, error) { func (m *defaultUserManagement) SetUser(ctx context.Context, in *SetUserRequest, opts ...grpc.CallOption) (*SetUserResponse, error) {
client := user_management.NewUserManagementClient(m.cli.Conn()) client := user_management.NewUserManagementClient(m.cli.Conn())
return client.SetUser(ctx, in, opts...) return client.SetUser(ctx, in, opts...)
} }
// 获取用户或者创建用户 // CreateUser 获取用户或者创建用户
func (m *defaultUserManagement) CreateUser(ctx context.Context, in *CreateUserRequest, opts ...grpc.CallOption) (*UserId, error) { func (m *defaultUserManagement) CreateUser(ctx context.Context, in *CreateUserRequest, opts ...grpc.CallOption) (*UserId, error) {
client := user_management.NewUserManagementClient(m.cli.Conn()) client := user_management.NewUserManagementClient(m.cli.Conn())
return client.CreateUser(ctx, in, opts...) return client.CreateUser(ctx, in, opts...)
} }
// CreateEmptyUser 创建空用户,用于关联游戏账号的空数据
func (m *defaultUserManagement) CreateEmptyUser(ctx context.Context, in *Empty, opts ...grpc.CallOption) (*UserId, error) { func (m *defaultUserManagement) CreateEmptyUser(ctx context.Context, in *Empty, opts ...grpc.CallOption) (*UserId, error) {
client := user_management.NewUserManagementClient(m.cli.Conn()) client := user_management.NewUserManagementClient(m.cli.Conn())
return client.CreateEmptyUser(ctx, in, opts...) return client.CreateEmptyUser(ctx, in, opts...)
} }
// GetUserById 通过 ID 获取用户
func (m *defaultUserManagement) GetUserById(ctx context.Context, in *UserId, opts ...grpc.CallOption) (*User, error) {
client := user_management.NewUserManagementClient(m.cli.Conn())
return client.GetUserById(ctx, in, opts...)
}