-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
51 lines (38 loc) · 848 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package main
import (
"flag"
"fmt"
"os"
"strings"
"sync"
"github.com/vadzim-z/go-translate-poc/cli"
)
var wg sync.WaitGroup
var sourceLang string
var targetLang string
var sourceText string
func init() {
flag.StringVar(&sourceLang, "s", "en", "Source language[en]")
flag.StringVar(&targetLang, "t", "ru", "Target language[ru]")
flag.StringVar(&sourceText, "st", "", "Text to translate")
}
func main() {
flag.Parse()
if flag.NFlag() == 0 {
fmt.Println("Options:")
flag.PrintDefaults()
os.Exit(1)
}
strChan := make(chan string)
wg.Add(1)
reqBody := &cli.RequestBody{
SourceLang: sourceLang,
TargetLang: targetLang,
SourceText: sourceText,
}
go cli.RequestTranslate(reqBody, strChan, &wg)
processedStr := strings.ReplaceAll(<-strChan, "+", " ")
fmt.Printf("%s\n", processedStr)
close(strChan)
wg.Wait()
}