mirror of
https://github.com/OwO-Network/DeepLX.git
synced 2025-04-19 06:03:25 +00:00
feat: return full alternatives
This commit is contained in:
parent
a5b256d7ad
commit
db722920cd
1
go.mod
1
go.mod
@ -10,6 +10,7 @@ require (
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/Jeffail/gabs/v2 v2.7.0 // indirect
|
||||
github.com/gin-contrib/sse v0.1.0 // indirect
|
||||
github.com/go-playground/locales v0.14.0 // indirect
|
||||
github.com/go-playground/universal-translator v0.18.0 // indirect
|
||||
|
2
go.sum
2
go.sum
@ -1,3 +1,5 @@
|
||||
github.com/Jeffail/gabs/v2 v2.7.0 h1:Y2edYaTcE8ZpRsR2AtmPu5xQdFDIthFG0jYhu5PY8kg=
|
||||
github.com/Jeffail/gabs/v2 v2.7.0/go.mod h1:dp5ocw1FvBBQYssgHsG7I1WYsiLRtkUaB1FEtSwvNUw=
|
||||
github.com/abadojack/whatlanggo v1.0.1 h1:19N6YogDnf71CTHm3Mp2qhYfkRdyvbgwWdd2EPxJRG4=
|
||||
github.com/abadojack/whatlanggo v1.0.1/go.mod h1:66WiQbSbJBIlOZMsvbKe5m6pzQovxCH9B/K8tQB2uoc=
|
||||
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
|
||||
|
13
main.go
13
main.go
@ -193,6 +193,7 @@ func main() {
|
||||
|
||||
body, _ := io.ReadAll(resp.Body)
|
||||
res := gjson.ParseBytes(body)
|
||||
|
||||
// display response
|
||||
// fmt.Println(res)
|
||||
if res.Get("error.code").String() == "-32600" {
|
||||
@ -210,10 +211,16 @@ func main() {
|
||||
"message": "Too Many Requests",
|
||||
})
|
||||
} else {
|
||||
var alternatives []string
|
||||
res.Get("result.texts.0.alternatives").ForEach(func(key, value gjson.Result) bool {
|
||||
alternatives = append(alternatives, value.Get("text").String())
|
||||
return true
|
||||
})
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"code": http.StatusOK,
|
||||
"id": id,
|
||||
"data": res.Get("result.texts.0.text").String(),
|
||||
"code": http.StatusOK,
|
||||
"id": id,
|
||||
"data": res.Get("result.texts.0.text").String(),
|
||||
"alternatives": alternatives,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user