-
Notifications
You must be signed in to change notification settings - Fork 0
/
command.go
47 lines (41 loc) · 1.1 KB
/
command.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
package nntp
import "io"
type Response struct {
Code int
Line string
Data io.Reader
}
// sends a low level command to nntp and checks the response code against the expected one.
func (c *Client) command(cmd string, expected int) (*Response, error) {
rc, line, err := c.sendCommand(cmd, expected)
if err != nil {
return nil, err
}
return &Response{
Code: rc,
Line: line,
}, nil
}
// sends a low level command to nntp and checks the response code against the expected one.
// Also handles Multi-line Data Block reponse
func (c *Client) multilineCommand(cmd string, expected int) (*Response, error) {
rc, line, err := c.sendCommand(cmd, expected)
if err != nil {
return nil, err
}
return &Response{
Code: rc,
Line: line,
Data: c.connection.DotReader(),
}, nil
}
// Helper to send the actual command and checks the reponse code against the expexted one.
func (c *Client) sendCommand(cmd string, expected int) (rc int, line string, err error) {
if err = c.connection.PrintfLine(cmd); err != nil {
return
}
if rc, line, err = c.connection.ReadCodeLine(expected); err != nil {
return
}
return
}