上传代码优化
This commit is contained in:
parent
10dfa52f8c
commit
0742fa1e89
@ -81,7 +81,7 @@ locp:
|
|||||||
break locp
|
break locp
|
||||||
}
|
}
|
||||||
} else {
|
} 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{
|
if err = this.WriteMsg(&pb.UserMessage{
|
||||||
MainType: comm.MainTypeNotify,
|
MainType: comm.MainTypeNotify,
|
||||||
SubType: comm.SubTypeErrorNotify,
|
SubType: comm.SubTypeErrorNotify,
|
||||||
@ -127,11 +127,11 @@ func (this *Agent) secAuth(msg *pb.UserMessage) error {
|
|||||||
if !utils.ValidSecretKey(msg.Sec) { //验证失败
|
if !utils.ValidSecretKey(msg.Sec) { //验证失败
|
||||||
return fmt.Errorf("key invalid")
|
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
|
base64Str := msg.Sec
|
||||||
dec, err := base64.StdEncoding.DecodeString(base64Str[35:])
|
dec, err := base64.StdEncoding.DecodeString(base64Str[35:])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -159,6 +159,10 @@ func decodeUserData(msg *pb.UserMessage) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
msg.Data = ad
|
msg.Data = ad
|
||||||
|
} else {
|
||||||
|
if this.UserId() == "" {
|
||||||
|
return fmt.Errorf("no login")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -211,6 +215,7 @@ func (this *Agent) Close() {
|
|||||||
func (this *Agent) messageDistribution(msg *pb.UserMessage) (err error) {
|
func (this *Agent) messageDistribution(msg *pb.UserMessage) (err error) {
|
||||||
reply := &pb.RPCMessageReply{}
|
reply := &pb.RPCMessageReply{}
|
||||||
log.Debugf("agent:%s uId:%s MessageDistribution msg:%s.%s", this.sessionId, this.uId, msg.MainType, msg.SubType)
|
log.Debugf("agent:%s uId:%s MessageDistribution msg:%s.%s", this.sessionId, this.uId, msg.MainType, msg.SubType)
|
||||||
|
|
||||||
servicePath := comm.Service_Worker
|
servicePath := comm.Service_Worker
|
||||||
if rule, ok := this.gateway.GetMsgDistribute(msg.MainType, msg.SubType); ok {
|
if rule, ok := this.gateway.GetMsgDistribute(msg.MainType, msg.SubType); ok {
|
||||||
servicePath = rule
|
servicePath = rule
|
||||||
|
@ -25,7 +25,7 @@ func (this *apiComp) Getlist(session comm.IUserSession, agrs map[string]interfac
|
|||||||
dels []string
|
dels []string
|
||||||
)
|
)
|
||||||
defer func() {
|
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 {
|
if code == pb.ErrorCode_Success {
|
||||||
go func() { //异步处理修改数据
|
go func() { //异步处理修改数据
|
||||||
this.module.modelItems.Pack_UpdateUserPack(session.GetUserId(), modifys...)
|
this.module.modelItems.Pack_UpdateUserPack(session.GetUserId(), modifys...)
|
||||||
|
@ -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) {
|
func (this *apiComp) SellItem(session comm.IUserSession, agrs map[string]interface{}, req *pb.ItemsSellItemReq) (code pb.ErrorCode) {
|
||||||
defer func() {
|
defer func() {
|
||||||
session.SendMsg(string(this.module.GetType()), SellItemResp, &pb.ItemsSellItemResp{})
|
session.SendMsg(string(this.module.GetType()), "sellitem", &pb.ItemsSellItemResp{})
|
||||||
}()
|
}()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -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) {
|
func (this *apiComp) Useitem(session comm.IUserSession, agrs map[string]interface{}, req *pb.ItemsUseItemReq) (code pb.ErrorCode) {
|
||||||
defer func() {
|
defer func() {
|
||||||
session.SendMsg(string(this.module.GetType()), UseItemResp, &pb.ItemsUseItemResp{})
|
session.SendMsg(string(this.module.GetType()), "useitem", &pb.ItemsUseItemResp{})
|
||||||
}()
|
}()
|
||||||
|
|
||||||
return
|
return
|
||||||
|
15
sys/cache/cache.go
vendored
15
sys/cache/cache.go
vendored
@ -19,10 +19,17 @@ type Cache struct {
|
|||||||
|
|
||||||
//初始化 redis 对象
|
//初始化 redis 对象
|
||||||
func (this *Cache) init() (err error) {
|
func (this *Cache) init() (err error) {
|
||||||
this.redis, err = redis.NewSys(
|
if this.options.Redis_IsCluster {
|
||||||
redis.SetRedisType(redis.Redis_Cluster),
|
this.redis, err = redis.NewSys(
|
||||||
redis.SetRedis_Cluster_Addr(this.options.Redis_Addr),
|
redis.SetRedisType(redis.Redis_Cluster),
|
||||||
redis.SetRedis_Cluster_Password(this.options.Redis_Password))
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
12
sys/cache/options.go
vendored
12
sys/cache/options.go
vendored
@ -11,8 +11,16 @@ import (
|
|||||||
*/
|
*/
|
||||||
type Option func(*Options)
|
type Option func(*Options)
|
||||||
type Options struct {
|
type Options struct {
|
||||||
Redis_Addr []string //redis 的集群地址
|
Redis_IsCluster bool //是否是集群
|
||||||
Redis_Password string //redis的密码
|
Redis_Addr []string //redis 的集群地址
|
||||||
|
Redis_Password string //redis的密码
|
||||||
|
}
|
||||||
|
|
||||||
|
//设置系统的集群地址
|
||||||
|
func Set_Redis_IsCluster(v bool) Option {
|
||||||
|
return func(o *Options) {
|
||||||
|
o.Redis_IsCluster = v
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//设置系统的集群地址
|
//设置系统的集群地址
|
||||||
|
Loading…
Reference in New Issue
Block a user