-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhandler.go
61 lines (59 loc) · 1.11 KB
/
handler.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
package main
import "fmt"
func ActionsHandler(args []string) bool {
switch args[1] {
case "ping":
conn := ConnectToPinit()
if conn != nil {
SendPing(conn)
conn.Close()
return true
}
return false
case "start":
if len(args) > 2 {
conn := ConnectToPinit()
if conn != nil {
StartService(conn, args[2])
conn.Close()
return true
}
} else {
fmt.Println(args[0] + ": error: missed service name")
return false
}
return false
case "stop":
if len(args) > 2 {
conn := ConnectToPinit()
if conn != nil {
StopService(conn, args[2])
conn.Close()
return true
}
} else {
fmt.Println(args[0] + ": error: missed service name")
return false
}
return false
case "restart":
if len(args) > 2 {
conn := ConnectToPinit()
if conn != nil {
result := StopService(conn, args[2])
if result == true {
StartService(conn, args[2])
}
conn.Close()
return true
}
} else {
fmt.Println(args[0] + ": error: missed service name")
return false
}
return false
default:
fmt.Println(args[0] + ": error: unknown action")
return false
}
}