Update nbnhhsh.go

This commit is contained in:
源文雨 2021-09-26 10:15:22 +08:00 committed by GitHub
parent c724be743d
commit 83199cf3aa

View File

@ -23,19 +23,25 @@ func init() {
func getValue(text string) []string { func getValue(text string) []string {
urlValues := url.Values{} urlValues := url.Values{}
urlValues.Add("text", text) urlValues.Add("text", text)
resp, _ := http.PostForm("https://lab.magiconch.com/api/nbnhhsh/guess", urlValues) resp, err := http.PostForm("https://lab.magiconch.com/api/nbnhhsh/guess", urlValues)
body, _ := ioutil.ReadAll(resp.Body) if err == nil {
resp.Close() body, err := ioutil.ReadAll(resp.Body)
json := gjson.ParseBytes(body) if err == nil {
res := make([]string, 0) resp.Body.Close()
var jsonPath string json := gjson.ParseBytes(body)
if json.Get("0.trans").Exists() { res := make([]string, 0)
jsonPath = "0.trans" var jsonPath string
} else { if json.Get("0.trans").Exists() {
jsonPath = "0.inputting" jsonPath = "0.trans"
} else {
jsonPath = "0.inputting"
}
for _, value := range json.Get(jsonPath).Array() {
res = append(res, value.String())
}
return res
}
return []string{err.Error()}
} }
for _, value := range json.Get(jsonPath).Array() { return []string{err.Error()}
res = append(res, value.String())
}
return res
} }