From 19779805ddf8fccdfe5aab2d88aae6a610250c4f Mon Sep 17 00:00:00 2001 From: zouap Date: Tue, 22 Mar 2022 11:15:55 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BB=A3=E7=A0=81=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zouap --- routers/search.go | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) 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 }