-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcommand_ignore.go
50 lines (39 loc) · 889 Bytes
/
command_ignore.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
package beanstalk
import (
"fmt"
"strconv"
"strings"
)
type IgnoreCommand struct {
Tube string
}
type IgnoreCommandResponse struct {
Count int
}
func (c IgnoreCommand) CommandLine() string {
return fmt.Sprintf("ignore %s", c.Tube)
}
func (c IgnoreCommand) Body() []byte {
return nil
}
func (c IgnoreCommand) HasResponseBody() bool {
return false
}
func (c IgnoreCommand) BuildResponse(responseLine string, _ []byte) (CommandResponse, error) {
switch {
case strings.HasPrefix(responseLine, "WATCHING"):
i := strings.LastIndex(responseLine, " ")
if i == -1 {
return nil, ErrUnexpectedResponse
}
count, err := strconv.Atoi(responseLine[i+1:])
if err != nil {
return nil, err
}
return IgnoreCommandResponse{count}, nil
case strings.EqualFold(responseLine, "NOT_IGNORED"):
return nil, ErrNotIgnored
default:
return nil, ErrUnexpectedResponse
}
}