-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
executable file
·104 lines (96 loc) · 2.34 KB
/
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package main
import (
config2 "cloud-client-go/config"
. "cloud-client-go/http_v2_client"
. "cloud-client-go/util"
"github.com/fatih/color"
"github.com/urfave/cli/v2"
"os"
"sync"
)
var (
wg sync.WaitGroup
)
func main() {
disLogo := displayLogo()
app := &cli.App{
Name: "cloud-client-go",
Usage: "Make a Cerence cloud request, such as ASR, TTS requests",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "input",
Aliases: []string{"i"},
Usage: "input file contains the request parameters",
EnvVars: []string{"INPUT"},
Required: true,
},
&cli.StringFlag{
Name: "output",
Aliases: []string{"o"},
Usage: "output file contains the returned response data from cloud",
EnvVars: []string{"OUTPUT"},
},
&cli.StringFlag{
Name: "audio",
Aliases: []string{"a"},
Usage: "audio file contains the returned audio data from cloud",
EnvVars: []string{"AUDIO"},
},
},
Action: func(context *cli.Context) error {
config := config2.ReadConfig(context.String("input"))
client := NewHttpV2Client(config.Host, config.Port, WithProtocol(config.Protocol), WithPath(config.Path), WithBoundary(config.GetBoundary()))
if client == nil {
ConsoleLogger.Fatalln("Can't new connection")
}
if err := client.Connect(); err != nil {
ConsoleLogger.Fatalln("Can't connect to server")
}
defer client.Close()
wg.Add(2)
//send
go func() {
defer func() {
if err := recover(); err != nil {
ConsoleLogger.Println(err)
}
}()
defer wg.Done()
Send(client, config)
ConsoleLogger.Println("Send done")
}()
//receive
go func() {
defer func() {
if err := recover(); err != nil {
ConsoleLogger.Println(err)
}
}()
defer wg.Done()
output := context.String("output")
audio := context.String("audio")
Receive(client, output, audio)
ConsoleLogger.Println("Receive done")
}()
wg.Wait()
ConsoleLogger.Println("Request Complete")
return nil
},
}
err := app.Run(os.Args)
if err != nil && !disLogo {
ConsoleLogger.Fatal(err)
}
}
func displayLogo() bool {
if len(os.Args) == 1 {
color.Cyan(logo)
return true
} else if len(os.Args) == 2 {
if os.Args[1] == "-h" || os.Args[1] == "--help" || os.Args[1] == "h" || os.Args[1] == "help" {
color.Cyan(logo)
return true
}
}
return false
}