/
monitor.go
64 lines (55 loc) · 1.25 KB
/
monitor.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
package types
import (
"errors"
)
// CmdInfo ...
type CmdInfo struct {
Name string
Version string
DownloadURLs []string
MD5 string
}
// Monitor ...
type Monitor struct {
cmd *EchoinCmd
}
// NewMonitor ...
func NewMonitor(cmd *EchoinCmd) *Monitor {
return &Monitor{cmd: cmd}
}
// MonitorResponse ...
type MonitorResponse struct {
Code uint
Msg []byte
}
// Download ...
func (r *Monitor) Download(info *CmdInfo, reply *MonitorResponse) error {
if info == nil || info.Name == "" {
return errors.New("CmdInfo can't be nil")
}
reply.Code = 0
reply.Msg = []byte("Received download info successfully")
r.cmd.DownloadChan <- info
return nil
}
// Upgrade ...
func (r *Monitor) Upgrade(info *CmdInfo, reply *MonitorResponse) error {
if info == nil || info.Name == "" {
return errors.New("CmdInfo can't be nil")
}
reply.Code = 0
reply.Msg = []byte("Received upgrade info successfully")
r.cmd.UpgradeChan <- info
return nil
}
// Kill ...
func (r *Monitor) Kill(info *CmdInfo, reply *MonitorResponse) error {
reply.Code = 0
reply.Msg = []byte("Received kill info successfully")
r.cmd.KillChan <- ""
return nil
}
// ReleaseName get the echoin release name
func (c *CmdInfo) ReleaseName() string {
return c.Name + "_" + c.Version
}