Browse Source

提交代码。

Signed-off-by: zouap <zouap@pcl.ac.cn>
tags/v1.22.3.2^2
zouap 3 years ago
parent
commit
19779805dd
1 changed files with 7 additions and 14 deletions
  1. +7
    -14
      routers/search.go

+ 7
- 14
routers/search.go View File

@@ -343,24 +343,17 @@ func sortRepo(Result []map[string]interface{}, SortBy string, ascending bool) {
orderBy = "num_watches"
}
sort.Slice(Result, func(i, j int) bool {
return getInt(Result[i][orderBy]) < getInt(Result[j][orderBy])
return getInt(Result[i][orderBy], orderBy) < getInt(Result[j][orderBy], orderBy)
})
}

func getInt(tmp interface{}) int64 {
switch tmp.(type) {
case string:
timeInt, err := strconv.ParseInt(tmp.(string), 10, 64)
if err == nil {
return timeInt
}
case int:
return int64(tmp.(int))

case int64:
return int64(tmp.(int64))
func getInt(tmp interface{}, orderBy string) int64 {
timeInt, err := strconv.ParseInt(fmt.Sprint(tmp), 10, 64)
if err == nil {
return timeInt
} else {
log.Info("convert " + orderBy + " error type=" + fmt.Sprint(tmp))
}
log.Info("convert err type=" + fmt.Sprint(tmp))
return -1
}



Loading…
Cancel
Save