-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
53 lines (43 loc) · 756 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
52
53
package main
import (
"fmt"
"os"
"os/signal"
"syscall"
)
const (
name = "EchoTool"
version = "1.0.0"
)
func main() {
cli := cli{}
config, err := cli.execute()
if err != nil {
fmt.Printf("%s: error: %s\n", cli.binName, err)
fmt.Printf("Type %s -help to see a list of all options.", cli.binName)
os.Exit(1)
}
if config.serverMode {
server := server{
config: config,
sigint: sigint(),
}
server.run()
} else {
client := client{
config: config,
sigint: sigint(),
}
client.run()
}
}
func sigint() *chan bool {
sigint := make(chan os.Signal, 1)
close := make(chan bool, 1)
signal.Notify(sigint, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
go func() {
<-sigint
close <- true
}()
return &close
}