Commit e298655b by xuzhenhao

增加了相应的错误返回

1 parent ac48ee16
...@@ -173,17 +173,17 @@ func SingleRangeRank(c *gin.Context) { ...@@ -173,17 +173,17 @@ func SingleRangeRank(c *gin.Context) {
nextrank := c.Query("nextrank") nextrank := c.Query("nextrank")
log.Printf("SingleRank uid[%s] gtid[%s] gid[%s] toptype[%s] prerank[%s] nextrank[%s]\n", uid, gtid, gid, toptype, prerank, nextrank) log.Printf("SingleRank uid[%s] gtid[%s] gid[%s] toptype[%s] prerank[%s] nextrank[%s]\n", uid, gtid, gid, toptype, prerank, nextrank)
igt, resIndex := sdkredis.IceGameTopRedisGetSingleUserRangeRankInfo(uid, gtid, gid, toptype, prerank, nextrank) igt, resIndex, err := sdkredis.IceGameTopRedisGetSingleUserRangeRankInfo(uid, gtid, gid, toptype, prerank, nextrank)
fmt.Println(igt) fmt.Println(igt)
infoList := make(map[string]interface{}, 0) infoList := make(map[string]interface{}, 0)
infoList["info_list"] = igt
infoList["user_index"] = resIndex
msg := new(Msg) msg := new(Msg)
if igt == nil { if err != nil {
err := errors.New("gametop name or game name not exist") log.Println(err)
msg.ErrMsg = err.Error() msg.ErrMsg = err.Error()
msg.ErrCode = "105101" msg.ErrCode = resIndex.(string)
} else { } else {
infoList["info_list"] = igt
infoList["user_index"] = resIndex.(int)
msg.ErrCode = "0" msg.ErrCode = "0"
msg.ErrMsg = "success" msg.ErrMsg = "success"
msg.Obj = infoList msg.Obj = infoList
......
...@@ -360,7 +360,7 @@ func IceGameTopRedisGetSingleUserRankInfo(uid string, gtid string, gid string, t ...@@ -360,7 +360,7 @@ func IceGameTopRedisGetSingleUserRankInfo(uid string, gtid string, gid string, t
/** /**
* 获取单个用户以及前后用户的排名信息 * 获取单个用户以及前后用户的排名信息
*/ */
func IceGameTopRedisGetSingleUserRangeRankInfo(uid string, gtid string, gid string, toptype string, prerank string, nextrank string) (res *[]IGT, resIndex int) { func IceGameTopRedisGetSingleUserRangeRankInfo(uid string, gtid string, gid string, toptype string, prerank string, nextrank string) (res *[]IGT, resIndex interface{}, err error) {
// 连接redis // 连接redis
redisConn := RedisClient.GetConn() redisConn := RedisClient.GetConn()
defer RedisClose(redisConn) defer RedisClose(redisConn)
...@@ -377,16 +377,18 @@ func IceGameTopRedisGetSingleUserRangeRankInfo(uid string, gtid string, gid stri ...@@ -377,16 +377,18 @@ func IceGameTopRedisGetSingleUserRangeRankInfo(uid string, gtid string, gid stri
return return
} }
} else { } else {
resIndex = "105207"
return return
} }
// 获取当前用户排名 // 获取当前用户排名
rank, err := RedisZRank(redisConn, "sortset:gtid:"+gtid+":gid:"+gid+":toptype:"+toptype, "ice_gametop:uid:"+uid+":gtid:"+gtid+":gid:"+gid+":toptype:"+toptype+":mykey") rank, err := RedisZRank(redisConn, "sortset:gtid:"+gtid+":gid:"+gid+":toptype:"+toptype, "ice_gametop:uid:"+uid+":gtid:"+gtid+":gid:"+gid+":toptype:"+toptype+":mykey")
if err != nil { if err != nil {
log.Println("RedisZRANK err[%v]", err) resIndex = "105202"
return return
} }
if rank == nil { if rank == nil {
return nil, 0 err = errors.New("用户未提交分数")
return nil, "105201", err
} }
rankIndex := int(rank.(int64)) rankIndex := int(rank.(int64))
...@@ -398,7 +400,7 @@ func IceGameTopRedisGetSingleUserRangeRankInfo(uid string, gtid string, gid stri ...@@ -398,7 +400,7 @@ func IceGameTopRedisGetSingleUserRangeRankInfo(uid string, gtid string, gid stri
} else { } else {
prerankIndex, err = strconv.Atoi(prerank) prerankIndex, err = strconv.Atoi(prerank)
if err != nil { if err != nil {
log.Println("String to Int err: ", err) resIndex = "105200"
return return
} }
} }
...@@ -407,7 +409,7 @@ func IceGameTopRedisGetSingleUserRangeRankInfo(uid string, gtid string, gid stri ...@@ -407,7 +409,7 @@ func IceGameTopRedisGetSingleUserRangeRankInfo(uid string, gtid string, gid stri
} else { } else {
nextrankIndex, err = strconv.Atoi(nextrank) nextrankIndex, err = strconv.Atoi(nextrank)
if err != nil { if err != nil {
log.Println("String to Int err: ", err) resIndex = "105200"
return return
} }
} }
...@@ -420,18 +422,18 @@ func IceGameTopRedisGetSingleUserRangeRankInfo(uid string, gtid string, gid stri ...@@ -420,18 +422,18 @@ func IceGameTopRedisGetSingleUserRangeRankInfo(uid string, gtid string, gid stri
// 排序 // 排序
var strList []string var strList []string
var sorterr error
if sorceorder == "0" { if sorceorder == "0" {
strList, sorterr = RedisSort(redisConn, "sortset:gtid:"+gtid+":gid:"+gid+":toptype:"+toptype, prerankIndex, nextrankIndex) strList, err = RedisSort(redisConn, "sortset:gtid:"+gtid+":gid:"+gid+":toptype:"+toptype, prerankIndex, nextrankIndex)
} else if sorceorder == "1" { } else if sorceorder == "1" {
strList, sorterr = RedisReverseSort(redisConn, "sortset:gtid:"+gtid+":gid:"+gid+":toptype:"+toptype, prerankIndex, nextrankIndex) strList, err = RedisReverseSort(redisConn, "sortset:gtid:"+gtid+":gid:"+gid+":toptype:"+toptype, prerankIndex, nextrankIndex)
} }
if sorterr != nil { if err != nil {
log.Println("RedisSort err[%v]", sorterr) resIndex = "105203"
log.Println("RedisSort err")
return return
} else if len(strList) == 0 { } else if len(strList) == 0 {
log.Println("rank has no data") err = errors.New("rank has no data")
resIndex = "105204"
} }
igt := make([]IGT, len(strList)/2) igt := make([]IGT, len(strList)/2)
...@@ -442,7 +444,8 @@ func IceGameTopRedisGetSingleUserRangeRankInfo(uid string, gtid string, gid stri ...@@ -442,7 +444,8 @@ func IceGameTopRedisGetSingleUserRangeRankInfo(uid string, gtid string, gid stri
var valuecount = 2 var valuecount = 2
_, err = RedisDBSelect(redisConn, 4) _, err = RedisDBSelect(redisConn, 4)
if err != nil { if err != nil {
log.Printf("select db err:", err) resIndex = "105205"
log.Printf("select db err")
} }
for i := 0; i < len(strList); i += 2 { for i := 0; i < len(strList); i += 2 {
startIndex := strings.Index(strList[i], "uid:") + 4 startIndex := strings.Index(strList[i], "uid:") + 4
...@@ -454,7 +457,6 @@ func IceGameTopRedisGetSingleUserRangeRankInfo(uid string, gtid string, gid stri ...@@ -454,7 +457,6 @@ func IceGameTopRedisGetSingleUserRangeRankInfo(uid string, gtid string, gid stri
} else { } else {
s = i / 2 s = i / 2
} }
log.Println("s:", s, "i:", i)
if prerankIndex+index-1 == rankIndex { if prerankIndex+index-1 == rankIndex {
resIndex = prerankIndex + index resIndex = prerankIndex + index
} }
...@@ -462,14 +464,13 @@ func IceGameTopRedisGetSingleUserRangeRankInfo(uid string, gtid string, gid stri ...@@ -462,14 +464,13 @@ func IceGameTopRedisGetSingleUserRangeRankInfo(uid string, gtid string, gid stri
igt[s].RankIndex = prerankIndex + index igt[s].RankIndex = prerankIndex + index
igt[s].MyKey = strList[i+1] igt[s].MyKey = strList[i+1]
//查询储存昵称以及头像url的redis //查询储存昵称以及头像url的redis
var err error
resultstr, err = RedisGetKV(redisConn, "GUID:"+igt[s].UID) resultstr, err = RedisGetKV(redisConn, "GUID:"+igt[s].UID)
if err != nil { if err != nil {
log.Println("get redis err:", err) resIndex = "105206"
} }
r, err := regexp.Compile(`\|([^\|])*\|`) r, err := regexp.Compile(`\|([^\|])*\|`)
if err != nil { if err != nil {
log.Println("err:", err) resIndex = "105200"
} }
// 使用正则匹配需要的值 // 使用正则匹配需要的值
result := r.FindAllString(resultstr, valuecount) result := r.FindAllString(resultstr, valuecount)
...@@ -492,7 +493,7 @@ func IceGameTopRedisGetSingleUserRangeRankInfo(uid string, gtid string, gid stri ...@@ -492,7 +493,7 @@ func IceGameTopRedisGetSingleUserRangeRankInfo(uid string, gtid string, gid stri
if err != nil { if err != nil {
log.Printf("select db err:", err) log.Printf("select db err:", err)
} }
return &igt, resIndex return &igt, resIndex, nil
} }
func IceGameTopRedisCreateRank(gtid string, gid string, toptype string, gtname string, sorcetype string, sorcesub string, sorceorder string) error { func IceGameTopRedisCreateRank(gtid string, gid string, toptype string, gtname string, sorcetype string, sorcesub string, sorceorder string) error {
// 连接redis // 连接redis
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!