优化pkg功能
This commit is contained in:
parent
6d8a3476a8
commit
383cdf1e02
1 changed files with 48 additions and 40 deletions
|
@ -59,7 +59,7 @@ func (a *Pkg) GetMsg() string {
|
||||||
}
|
}
|
||||||
defer req.Body.Close()
|
defer req.Body.Close()
|
||||||
|
|
||||||
fmt.Println("aur url:", url)
|
fmt.Println("aur suggest url:", url)
|
||||||
re, err := io.ReadAll(req.Body)
|
re, err := io.ReadAll(req.Body)
|
||||||
// fmt.Println(string(re))
|
// fmt.Println(string(re))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -70,26 +70,31 @@ func (a *Pkg) GetMsg() string {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
}
|
}
|
||||||
if len(suggestions) > 0 {
|
// println(len(suggestions))
|
||||||
searchUrl := "https://aur.archlinux.org/rpc/v5/search/" + suggestions[0] + "?by=name"
|
if len(suggestions) == 0 {
|
||||||
searchReq, err := http.Get(searchUrl)
|
return "没有找到相关软件"
|
||||||
if err != nil {
|
}
|
||||||
fmt.Println(err)
|
searchUrl := "https://aur.archlinux.org/rpc/v5/search/" + suggestions[0] + "?by=name"
|
||||||
}
|
searchReq, err := http.Get(searchUrl)
|
||||||
defer searchReq.Body.Close()
|
if err != nil {
|
||||||
searchRe, err := io.ReadAll(searchReq.Body)
|
fmt.Println(err)
|
||||||
if err != nil {
|
}
|
||||||
fmt.Println(err)
|
defer searchReq.Body.Close()
|
||||||
}
|
searchRe, err := io.ReadAll(searchReq.Body)
|
||||||
var searchMap map[string]interface{}
|
if err != nil {
|
||||||
err = json.Unmarshal(searchRe, &searchMap)
|
fmt.Println(err)
|
||||||
if err != nil {
|
}
|
||||||
fmt.Println(err)
|
var searchMap map[string]interface{}
|
||||||
}
|
err = json.Unmarshal(searchRe, &searchMap)
|
||||||
// 增加根据投票人数排序
|
if err != nil {
|
||||||
searchResults := searchMap["results"].([]interface{})
|
fmt.Println(err)
|
||||||
maxVotes := 0.0
|
}
|
||||||
var searchResult map[string]interface{}
|
searchResults := searchMap["results"].([]interface{})
|
||||||
|
// println("searchResults:", len(searchResults))
|
||||||
|
maxVotes := 0.0
|
||||||
|
var searchResult map[string]interface{}
|
||||||
|
// 增加根据投票人数排序
|
||||||
|
if len(searchResults) > 1 {
|
||||||
for _, result := range searchResults {
|
for _, result := range searchResults {
|
||||||
resultMap := result.(map[string]interface{})
|
resultMap := result.(map[string]interface{})
|
||||||
numVotes := resultMap["NumVotes"].(float64)
|
numVotes := resultMap["NumVotes"].(float64)
|
||||||
|
@ -98,26 +103,29 @@ func (a *Pkg) GetMsg() string {
|
||||||
searchResult = resultMap
|
searchResult = resultMap
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
fmt.Println(len(searchResult))
|
||||||
maintainer, ok := searchResult["Maintainer"].(string)
|
} else if len(searchResults) == 1 {
|
||||||
if !ok {
|
searchResult = searchResults[0].(map[string]interface{})
|
||||||
maintainer = "孤儿包"
|
|
||||||
}
|
|
||||||
last_update := time.Unix(int64(searchResult["LastModified"].(float64)), 0).Format("2006-01-02 15:04:05")
|
|
||||||
var msg string
|
|
||||||
msg += "仓库:AUR\n"
|
|
||||||
msg += "包名:" + searchResult["Name"].(string) + "\n"
|
|
||||||
msg += "版本:" + searchResult["Version"].(string) + "\n"
|
|
||||||
msg += "描述:" + searchResult["Description"].(string) + "\n"
|
|
||||||
msg += "维护者:" + maintainer + "\n"
|
|
||||||
msg += "链接:" + searchResult["URL"].(string) + "\n"
|
|
||||||
msg += "更新时间:" + last_update + "\n"
|
|
||||||
|
|
||||||
fmt.Println(msg)
|
|
||||||
return msg
|
|
||||||
} else {
|
|
||||||
return "没有找到相关软件"
|
|
||||||
}
|
}
|
||||||
|
maintainer, ok := searchResult["Maintainer"].(string)
|
||||||
|
if !ok {
|
||||||
|
maintainer = "孤儿包"
|
||||||
|
}
|
||||||
|
println("maintainer:", maintainer)
|
||||||
|
// last_update := ''
|
||||||
|
last_update := time.Unix(int64(searchResult["LastModified"].(float64)), 0).Format("2006-01-02 15:04:05")
|
||||||
|
|
||||||
|
var msg string
|
||||||
|
msg += "仓库:AUR\n"
|
||||||
|
msg += "包名:" + searchResult["Name"].(string) + "\n"
|
||||||
|
msg += "版本:" + searchResult["Version"].(string) + "\n"
|
||||||
|
msg += "描述:" + searchResult["Description"].(string) + "\n"
|
||||||
|
msg += "维护者:" + maintainer + "\n"
|
||||||
|
msg += "链接:" + searchResult["URL"].(string) + "\n"
|
||||||
|
msg += "更新时间:" + last_update
|
||||||
|
|
||||||
|
fmt.Println(msg)
|
||||||
|
return msg
|
||||||
|
|
||||||
}
|
}
|
||||||
result := resultSlipe[0].(map[string]interface{})
|
result := resultSlipe[0].(map[string]interface{})
|
||||||
|
|
Loading…
Reference in a new issue