-
Notifications
You must be signed in to change notification settings - Fork 0
/
console.go
132 lines (119 loc) · 2.62 KB
/
console.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package gomsf
import "fmt"
const (
cslcreate = "console.create"
csllist = "console.list"
cslrm = "console.destroy"
cslread = "console.read"
cslwrite = "console.write"
csltabs = "console.tabs"
cslsskill = "console.session_kill"
cslssdetach = "console.session_detach"
)
type ConsoleInfo struct {
Id string `msgpack:"id"`
Prompt string `msgpack:"prompt"`
Busy bool `msgpack:"busy"`
}
type ConsoleDataInfo struct {
Data string `msgpack:"data"`
Prompt string `msgpack:"prompt"`
Busy bool `msgpack:"busy"`
}
type ConsoleTabInfo struct {
Tabs []string `msgpack:"tabs"`
}
func ConsoleCreate(cli MsfCli, token string) (*ConsoleInfo, error) {
var (
retv *ConsoleInfo
sts = []string{cslcreate, token}
)
err := cli.Send(sts, &retv)
if err != nil {
return nil, err
}
return retv, nil
}
func ConsoleDestory(cli MsfCli, token, consoleId string) (*Generic, error) {
var (
retv *Generic
sts = []string{cslrm, token, consoleId}
)
err := cli.Send(sts, &retv)
if err != nil {
return nil, err
}
return retv, nil
}
func ConsoleList(cli MsfCli, token string) ([]*ConsoleInfo, error) {
var (
retv []*ConsoleInfo
sts = []string{csllist, token}
)
err := cli.Send(sts, &retv)
if err != nil {
return nil, err
}
return retv, nil
}
func ConsoleWrite(cli MsfCli, token, consoleId string, data []byte) error {
var (
sts = []string{cslwrite, token, consoleId, string(data)}
)
var ret struct {
Wrote int `msgpack:"wrote"`
}
var r = &ret
err := cli.Send(sts, &r)
if err != nil {
return err
}
if ret.Wrote != len(data) {
return fmt.Errorf("write %d, but expect %d", ret.Wrote, len(data))
}
return nil
}
func ConsoleRead(cli MsfCli, token, consoleId string) (*ConsoleDataInfo, error) {
var (
retv *ConsoleDataInfo
sts = []string{cslread, token, consoleId}
)
err := cli.Send(sts, &retv)
if err != nil {
return nil, err
}
return retv, nil
}
func ConsoleSessDetach(cli MsfCli, token, consoleId string) (*Generic, error) {
var (
retv *Generic
sts = []string{cslssdetach, token, consoleId}
)
err := cli.Send(sts, &retv)
if err != nil {
return nil, err
}
return retv, nil
}
func ConsoleSessKill(cli MsfCli, token, consoleId string) (*Generic, error) {
var (
retv *Generic
sts = []string{cslsskill, token, consoleId}
)
err := cli.Send(sts, &retv)
if err != nil {
return nil, err
}
return retv, nil
}
func ConsoleTabs(cli MsfCli, token, consoleId, input string) (*ConsoleTabInfo, error) {
var (
retv *ConsoleTabInfo
sts = []string{csltabs, token, consoleId, input}
)
err := cli.Send(sts, &retv)
if err != nil {
return nil, err
}
return retv, nil
}