Changeset 30 in code


Ignore:
Timestamp:
Feb 10, 2024, 11:39:49 AM (16 months ago)
Author:
yakumo.izuru
Message:

Assume the instance is down if the translation output is blank

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/cmd/suwako/main.go

    r29 r30  
    1 // $TheSupernovaDuo: suwako,v 1.5.4 2024/01/14 21:21:50 yakumo_izuru Exp $
     1// $TheSupernovaDuo: suwako,v 1.5.5 2024/01/20 21:07:30 yakumo_izuru Exp $
    22// Command line client for SimplyTranslate, a privacy friendly frontend to other translation engines
    33package main
     
    4343                return err
    4444        }
    45         conf.engine = cfg.Section("simplytranslate").Key("engine").String()
    46         conf.instance = cfg.Section("simplytranslate").Key("instance").String()
     45        conf.engine = cfg.Section("suwako").Key("engine").String()
     46        conf.instance = cfg.Section("suwako").Key("instance").String()
    4747
    4848        return nil
     
    6666
    6767        // Load configuration file
    68         home, err := os.UserHomeDir()
     68        config, err := os.UserConfigDir()
    6969        errCheck(err)
    70         cfgfile := home + "/.suwako/suwako.conf"
     70        cfgfile := config + "/suwako/suwako.ini"
    7171        iniLoad(cfgfile)
    7272
     
    8383
    8484        // Construct the final path to query
    85         var queryURL = conf.instance + "?engine=" + conf.engine + "&from=" + source + "&to=" + target + "&text=" + encInput
     85        var queryURL = conf.instance + "/api/translate/" + "?engine=" + conf.engine + "&from=" + source + "&to=" + target + "&text=" + encInput
    8686
    8787        // Shoot danmaku to path
     
    9393        _ = json.NewDecoder(resp.Body).Decode(&translate)
    9494        errCheck(err)
    95         fmt.Printf("%v\n",translate.Output)
     95        if len(translate.Output) == 0 {
     96                log.Fatal("There was no output, maybe the server was down?")
     97        } else {
     98                fmt.Printf("%v\n", translate.Output)
     99        }
    96100}
Note: See TracChangeset for help on using the changeset viewer.