v/GTT
1
0
mirror of https://github.com/eeeXun/GTT.git synced 2025-05-21 01:50:36 -07:00

refactor(argostranslate): use PostForm instead of Post

The newline of message in url.Values in PostForm doesn't need to be
replaced by `\n`
This commit is contained in:
eeeXun 2023-02-04 13:31:56 +08:00
parent 513ad36470
commit 8a141e641e

View File

@ -1,14 +1,13 @@
package argostranslate
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"gtt/internal/lock"
"io/ioutil"
"net/http"
"strings"
"net/url"
)
const (
@ -57,15 +56,12 @@ func (t *ArgosTranslate) Translate(message string) (
err error) {
var data interface{}
res, err := http.Post(textURL,
"application/json",
bytes.NewBuffer([]byte(fmt.Sprintf(`{
"q": "%s",
"source": "%s",
"target": "%s" }`,
strings.Replace(message, "\n", `\n`, -1),
langCode[t.srcLang],
langCode[t.dstLang]))))
res, err := http.PostForm(textURL,
url.Values{
"q": {message},
"source": {langCode[t.srcLang]},
"target": {langCode[t.dstLang]},
})
if err != nil {
return "", "", "", err
}