Assume the instance is down if the translation output is blank

Signed-off-by: Izuru Yakumo <yakumo.izuru@chaotic.ninja>

git-svn-id: https://svn.yakumo.dev/yakumo.izuru/suwako/trunk@30 0b558ee1-521d-8b46-a41b-40029c97c055
This commit is contained in:
yakumo.izuru 2024-02-10 11:39:49 +00:00
parent 3ee59b76b3
commit a31a857422

View File

@ -1,4 +1,4 @@
// $TheSupernovaDuo: suwako,v 1.5.4 2024/01/14 21:21:50 yakumo_izuru Exp $
// $TheSupernovaDuo: suwako,v 1.5.5 2024/01/20 21:07:30 yakumo_izuru Exp $
// Command line client for SimplyTranslate, a privacy friendly frontend to other translation engines
package main
@ -42,8 +42,8 @@ func iniLoad(file string) error {
if err != nil {
return err
}
conf.engine = cfg.Section("simplytranslate").Key("engine").String()
conf.instance = cfg.Section("simplytranslate").Key("instance").String()
conf.engine = cfg.Section("suwako").Key("engine").String()
conf.instance = cfg.Section("suwako").Key("instance").String()
return nil
}
@ -65,9 +65,9 @@ func main() {
flagParse()
// Load configuration file
home, err := os.UserHomeDir()
config, err := os.UserConfigDir()
errCheck(err)
cfgfile := home + "/.suwako/suwako.conf"
cfgfile := config + "/suwako/suwako.ini"
iniLoad(cfgfile)
// Verify command-line inputs
@ -82,7 +82,7 @@ func main() {
var encInput = url.PathEscape(input)
// Construct the final path to query
var queryURL = conf.instance + "?engine=" + conf.engine + "&from=" + source + "&to=" + target + "&text=" + encInput
var queryURL = conf.instance + "/api/translate/" + "?engine=" + conf.engine + "&from=" + source + "&to=" + target + "&text=" + encInput
// Shoot danmaku to path
resp, err := http.Get(queryURL)
@ -92,5 +92,9 @@ func main() {
// Decode JSON response, discard everything else, print to standard output
_ = json.NewDecoder(resp.Body).Decode(&translate)
errCheck(err)
fmt.Printf("%v\n",translate.Output)
if len(translate.Output) == 0 {
log.Fatal("There was no output, maybe the server was down?")
} else {
fmt.Printf("%v\n", translate.Output)
}
}