pkg增加根据投票人数排序搜索结果
This commit is contained in:
parent
46dde0cd18
commit
6d8a3476a8
1 changed files with 16 additions and 3 deletions
|
@ -21,6 +21,8 @@ func (a *Pkg) GetMsg() string {
|
|||
}
|
||||
// 去除换行符
|
||||
raw_msg := strings.TrimRight(a.RawMsg, "\n")
|
||||
raw_msg = strings.TrimRight(raw_msg, "\r")
|
||||
|
||||
fmt.Println("raw_msg:", raw_msg)
|
||||
parms := strings.Split(raw_msg, " ")
|
||||
|
||||
|
@ -32,12 +34,12 @@ func (a *Pkg) GetMsg() string {
|
|||
fmt.Println("pkg url:", url)
|
||||
req, err := http.Get(url)
|
||||
if err != nil {
|
||||
return err.Error()
|
||||
return "服务器网络错误!"
|
||||
}
|
||||
defer req.Body.Close()
|
||||
body, err := io.ReadAll(req.Body)
|
||||
if err != nil {
|
||||
return err.Error()
|
||||
return "数据解析错误!"
|
||||
}
|
||||
// fmt.Println("pkg body:", string(body))
|
||||
// var pkg []Package
|
||||
|
@ -84,8 +86,19 @@ func (a *Pkg) GetMsg() string {
|
|||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
// 增加根据投票人数排序
|
||||
searchResults := searchMap["results"].([]interface{})
|
||||
searchResult := searchResults[0].(map[string]interface{})
|
||||
maxVotes := 0.0
|
||||
var searchResult map[string]interface{}
|
||||
for _, result := range searchResults {
|
||||
resultMap := result.(map[string]interface{})
|
||||
numVotes := resultMap["NumVotes"].(float64)
|
||||
if numVotes > maxVotes {
|
||||
maxVotes = numVotes
|
||||
searchResult = resultMap
|
||||
}
|
||||
}
|
||||
|
||||
maintainer, ok := searchResult["Maintainer"].(string)
|
||||
if !ok {
|
||||
maintainer = "孤儿包"
|
||||
|
|
Loading…
Reference in a new issue