mirror of
https://github.com/eeeXun/GTT.git
synced 2025-05-18 00:30:40 -07:00
refactor: declare data as map[string]interface
instead of interface
data in Translate function of ApertiumTranslate and ArgosTranslate is a map[string]interface, so no need to declare it as interface then convert it to map[string]interface
This commit is contained in:
parent
5fcb72cbb2
commit
df42efc81d
@ -51,7 +51,7 @@ func (t *ApertiumTranslate) SwapLang() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t *ApertiumTranslate) Translate(message string) (translation, definition, partOfSpeech string, err error) {
|
func (t *ApertiumTranslate) Translate(message string) (translation, definition, partOfSpeech string, err error) {
|
||||||
var data interface{}
|
var data map[string]interface{}
|
||||||
|
|
||||||
urlStr := fmt.Sprintf(
|
urlStr := fmt.Sprintf(
|
||||||
textURL,
|
textURL,
|
||||||
@ -71,11 +71,11 @@ func (t *ApertiumTranslate) Translate(message string) (translation, definition,
|
|||||||
return "", "", "", err
|
return "", "", "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(data.(map[string]interface{})) > 0 {
|
if len(data) > 0 {
|
||||||
switch res.StatusCode {
|
switch res.StatusCode {
|
||||||
case 200:
|
case 200:
|
||||||
translation += fmt.Sprintf("%v",
|
translation += fmt.Sprintf("%v",
|
||||||
data.(map[string]interface{})["responseData"].(map[string]interface{})["translatedText"])
|
data["responseData"].(map[string]interface{})["translatedText"])
|
||||||
default:
|
default:
|
||||||
return "", "", "", errors.New(
|
return "", "", "", errors.New(
|
||||||
fmt.Sprintf("%s does not support translate from %s to %s.\nSee available pair on %s",
|
fmt.Sprintf("%s does not support translate from %s to %s.\nSee available pair on %s",
|
||||||
|
@ -51,7 +51,7 @@ func (t *ArgosTranslate) SwapLang() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t *ArgosTranslate) Translate(message string) (translation, definition, partOfSpeech string, err error) {
|
func (t *ArgosTranslate) Translate(message string) (translation, definition, partOfSpeech string, err error) {
|
||||||
var data interface{}
|
var data map[string]interface{}
|
||||||
|
|
||||||
res, err := http.PostForm(textURL,
|
res, err := http.PostForm(textURL,
|
||||||
url.Values{
|
url.Values{
|
||||||
@ -70,9 +70,8 @@ func (t *ArgosTranslate) Translate(message string) (translation, definition, par
|
|||||||
return "", "", "", err
|
return "", "", "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(data.(map[string]interface{})) > 0 {
|
if len(data) > 0 {
|
||||||
translation += fmt.Sprintf("%v",
|
translation += fmt.Sprintf("%v", data["translatedText"])
|
||||||
data.(map[string]interface{})["translatedText"])
|
|
||||||
|
|
||||||
return translation, definition, partOfSpeech, nil
|
return translation, definition, partOfSpeech, nil
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user