Achieved some more progress
Signed-off-by: Aoi K <koizumi.aoi@kyoko-project.wer.ee> git-svn-id: file:///srv/svn/repo/suwako/trunk@2 0b558ee1-521d-8b46-a41b-40029c97c055
This commit is contained in:
parent
e3f7b5b83b
commit
82dd32fba9
2
go.mod
2
go.mod
@ -1,3 +1,3 @@
|
||||
module git.076.ne.jp/novaburst/stcli
|
||||
module git.kyoko-project.wer.ee/koizumi.aoi/stcli-go
|
||||
|
||||
go 1.18
|
||||
|
42
main.go
42
main.go
@ -5,10 +5,10 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"flag"
|
||||
"io"
|
||||
"path/filepath"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
)
|
||||
|
||||
@ -25,35 +25,41 @@ func init() {
|
||||
flag.StringVar(&instanceURL, "i", "https://translate.bus-hit.me/api/translate/", "Instance for SimplyTranslate (default: https://translate.bus-hit.me)")
|
||||
flag.StringVar(&engine, "e", "google", "Translation engine (default: google)")
|
||||
flag.StringVar(&fromLang, "f", "auto", "Source language (default: auto)")
|
||||
flag.StringVar(&toLang, "t", "", "Target language")
|
||||
flag.StringVar(&text, "T", "", "Text to translate")
|
||||
flag.StringVar(&toLang, "t", "", "Target language (default: unset)")
|
||||
flag.StringVar(&text, "T", "", "Text to translate (default: unset)")
|
||||
}
|
||||
func main() {
|
||||
// Start parsing
|
||||
flag.Parse()
|
||||
|
||||
// I assume this works?
|
||||
if len(text) == 0 {
|
||||
log.Printf("Text to translate is required. \n")
|
||||
os.Exit(1)
|
||||
} else if len(toLang) == 0 {
|
||||
log.Printf("Target language is missing. \n")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Hand-craft the request URL
|
||||
queryURL := instanceURL + "?engine=" + engine + "&from=" + fromLang + "&to=" + toLang + "&text=" + text
|
||||
|
||||
// Make a request to said URL
|
||||
resp, err := http.Get(queryURL)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
resp, err1 := http.Get(queryURL)
|
||||
if err1 != nil {
|
||||
log.Printf("Request could not be processed due to %s\n", err1)
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
output := body
|
||||
|
||||
|
||||
output, err2 := io.ReadAll(resp.Body)
|
||||
|
||||
if err2 != nil {
|
||||
panic(errno)
|
||||
}
|
||||
|
||||
// Well...
|
||||
fmt.Printf("Input: %s \n", text)
|
||||
fmt.Printf("Output: %s \n", output)
|
||||
}
|
||||
func printUsage() {
|
||||
fmt.Printf("Usage for %s : \n", filepath.Base(os.Args[0]))
|
||||
fmt.Printf("-e \t Use the specified translation engine (default: google)\n")
|
||||
fmt.Printf("-f \t (default: auto)\n")
|
||||
fmt.Printf("-t \t (default: none)\n")
|
||||
fmt.Printf("-T \t Text to translate\n")
|
||||
|
||||
os.Exit(1)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user