diff --git a/routers/search.go b/routers/search.go index 1dc2fb57f..2fdd89b75 100644 --- a/routers/search.go +++ b/routers/search.go @@ -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 }