上传代码优化

This commit is contained in:
liwei1dao 2022-06-30 16:13:00 +08:00
parent 10dfa52f8c
commit 0742fa1e89
6 changed files with 32 additions and 12 deletions

View File

@ -81,7 +81,7 @@ locp:
break locp
}
} else {
data, _ := anypb.New(&pb.NotifyErrorNotifyPush{ReqMainType: msg.MainType, ReqSubType: msg.SubType, Code: pb.ErrorCode_SecKeyInvalid})
data, _ := anypb.New(&pb.NotifyErrorNotifyPush{ReqMainType: msg.MainType, ReqSubType: msg.SubType, Code: pb.ErrorCode_SecKeyInvalid, Message: err.Error()})
if err = this.WriteMsg(&pb.UserMessage{
MainType: comm.MainTypeNotify,
SubType: comm.SubTypeErrorNotify,
@ -127,11 +127,11 @@ func (this *Agent) secAuth(msg *pb.UserMessage) error {
if !utils.ValidSecretKey(msg.Sec) { //验证失败
return fmt.Errorf("key invalid")
}
return decodeUserData(msg)
return this.decodeUserData(msg)
}
//解码
func decodeUserData(msg *pb.UserMessage) error {
func (this *Agent) decodeUserData(msg *pb.UserMessage) error {
base64Str := msg.Sec
dec, err := base64.StdEncoding.DecodeString(base64Str[35:])
if err != nil {
@ -159,6 +159,10 @@ func decodeUserData(msg *pb.UserMessage) error {
return err
}
msg.Data = ad
} else {
if this.UserId() == "" {
return fmt.Errorf("no login")
}
}
return nil
}
@ -211,6 +215,7 @@ func (this *Agent) Close() {
func (this *Agent) messageDistribution(msg *pb.UserMessage) (err error) {
reply := &pb.RPCMessageReply{}
log.Debugf("agent:%s uId:%s MessageDistribution msg:%s.%s", this.sessionId, this.uId, msg.MainType, msg.SubType)
servicePath := comm.Service_Worker
if rule, ok := this.gateway.GetMsgDistribute(msg.MainType, msg.SubType); ok {
servicePath = rule

View File

@ -25,7 +25,7 @@ func (this *apiComp) Getlist(session comm.IUserSession, agrs map[string]interfac
dels []string
)
defer func() {
session.SendMsg(string(this.module.GetType()), GetlistResp, &pb.ItemsGetlistResp{Grids: grids})
session.SendMsg(string(this.module.GetType()), "getlist", &pb.ItemsGetlistResp{Grids: grids})
if code == pb.ErrorCode_Success {
go func() { //异步处理修改数据
this.module.modelItems.Pack_UpdateUserPack(session.GetUserId(), modifys...)

View File

@ -14,7 +14,7 @@ func (this *apiComp) SellItemCheck(session comm.IUserSession, req *pb.ItemsSellI
//出售道具
func (this *apiComp) SellItem(session comm.IUserSession, agrs map[string]interface{}, req *pb.ItemsSellItemReq) (code pb.ErrorCode) {
defer func() {
session.SendMsg(string(this.module.GetType()), SellItemResp, &pb.ItemsSellItemResp{})
session.SendMsg(string(this.module.GetType()), "sellitem", &pb.ItemsSellItemResp{})
}()
return
}

View File

@ -14,7 +14,7 @@ func (this *apiComp) UseitemCheck(session comm.IUserSession, req *pb.ItemsUseIte
//使用道具
func (this *apiComp) Useitem(session comm.IUserSession, agrs map[string]interface{}, req *pb.ItemsUseItemReq) (code pb.ErrorCode) {
defer func() {
session.SendMsg(string(this.module.GetType()), UseItemResp, &pb.ItemsUseItemResp{})
session.SendMsg(string(this.module.GetType()), "useitem", &pb.ItemsUseItemResp{})
}()
return

7
sys/cache/cache.go vendored
View File

@ -19,10 +19,17 @@ type Cache struct {
//初始化 redis 对象
func (this *Cache) init() (err error) {
if this.options.Redis_IsCluster {
this.redis, err = redis.NewSys(
redis.SetRedisType(redis.Redis_Cluster),
redis.SetRedis_Cluster_Addr(this.options.Redis_Addr),
redis.SetRedis_Cluster_Password(this.options.Redis_Password))
} else {
this.redis, err = redis.NewSys(
redis.SetRedisType(redis.Redis_Single),
redis.SetRedis_Single_Addr(this.options.Redis_Addr[0]),
redis.SetRedis_Single_Password(this.options.Redis_Password))
}
return
}

View File

@ -11,10 +11,18 @@ import (
*/
type Option func(*Options)
type Options struct {
Redis_IsCluster bool //是否是集群
Redis_Addr []string //redis 的集群地址
Redis_Password string //redis的密码
}
//设置系统的集群地址
func Set_Redis_IsCluster(v bool) Option {
return func(o *Options) {
o.Redis_IsCluster = v
}
}
//设置系统的集群地址
func Set_Redis_Addr(v []string) Option {
return func(o *Options) {