-
Notifications
You must be signed in to change notification settings - Fork 0
/
ymlCommands.go
59 lines (49 loc) · 1.08 KB
/
ymlCommands.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
package beanstalkg
import (
"fmt"
"strings"
)
func (c *Connection) getYMLResp(cmd string) ([]byte, error) {
resp, err := c.GetResp(cmd)
if err != nil {
return nil, err
}
var bodyLen int
switch {
case strings.HasPrefix(resp, "OK"):
_, err = fmt.Sscanf(resp, "OK %d\r\n", &bodyLen)
if err != nil {
return nil, err
}
default:
return nil, stringToError(resp)
}
return c.readBody(bodyLen)
}
func (c *Connection) StatsJob(id int) ([]byte, error) {
cmd := fmt.Sprintf("stats-job %d\r\n", id)
return c.getYMLResp(cmd)
}
func (c *Connection) StatsTube(tubename string) (*TubeStats, error) {
cmd := fmt.Sprintf("stats-tube %s\r\n", tubename)
b, err := c.getYMLResp(cmd)
if err != nil {
return nil, err
}
return tubeStatsParser(b), nil
}
func (c *Connection) Stats() (*InstanceStats, error) {
b, err := c.getYMLResp("stats\r\n")
if err != nil {
return nil, err
}
res := statsParser(b)
return res, nil
}
func (c *Connection) ListTubes() ([]string, error) {
b, err := c.getYMLResp("list-tubes\r\n")
if err != nil {
return []string{}, err
}
return listParser(b), nil
}