From a31a857422300c3b9649d31d1d690df1cdf69dcc Mon Sep 17 00:00:00 2001 From: "yakumo.izuru" Date: Sat, 10 Feb 2024 11:39:49 +0000 Subject: [PATCH] Assume the instance is down if the translation output is blank Signed-off-by: Izuru Yakumo git-svn-id: https://svn.yakumo.dev/yakumo.izuru/suwako/trunk@30 0b558ee1-521d-8b46-a41b-40029c97c055 --- cmd/suwako/main.go | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/cmd/suwako/main.go b/cmd/suwako/main.go index bf2e275..147baaf 100644 --- a/cmd/suwako/main.go +++ b/cmd/suwako/main.go @@ -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) + } }