44 lines
1.1 KiB
Go
44 lines
1.1 KiB
Go
package user
|
|
|
|
import (
|
|
"context"
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/modules"
|
|
"go_dreamfactory/pb"
|
|
"go_dreamfactory/sys/cache"
|
|
"go_dreamfactory/utils"
|
|
|
|
"github.com/liwei1dao/lego/core"
|
|
"github.com/liwei1dao/lego/sys/log"
|
|
)
|
|
|
|
type UserComp struct {
|
|
modules.MComp_GateComp
|
|
module *User
|
|
}
|
|
|
|
func (this *UserComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
|
|
this.MComp_GateComp.Init(service, module, comp, options)
|
|
this.module = module.(*User)
|
|
return
|
|
}
|
|
|
|
//创角
|
|
func (this *UserComp) Create(ctx context.Context, session comm.IUserSession, req *pb.UserCreateReq) error {
|
|
defer utils.TraceFunc(session.GetUserId(), "user", "create", req, nil)
|
|
user := cache.Defsys.Get(session.GetUserId())
|
|
if user == nil {
|
|
log.Errorf("user no exist")
|
|
session.SendMsg("user", "create", pb.ErrorCode_UserSessionNobeing, nil)
|
|
return nil
|
|
}
|
|
|
|
user.UserData.NiceName = req.NickName
|
|
err := cache.Defsys.Update(user)
|
|
if err != nil {
|
|
log.Errorf("cache update err")
|
|
}
|
|
session.SendMsg("user", "create", pb.ErrorCode_Success, &pb.UserCreateRsp{})
|
|
return nil
|
|
}
|