-- import "github.com/andrewstuart/nntp"
const (
ArticleFound = 220
NoArticleWithId = 430
)
const (
AuthAccepted = 281
PasswordNeeded = 381
AuthNeeded = 480
BadAuth = 481
ConnsExceeded = 502
)
https://tools.ietf.org/html/rfc4643
const (
GroupJoined = 211
NoSuchGroup = 411
)
const (
CapabilitiesFollow = 101
)
const HeadersFollow = 221
const (
InfoFollows = 215
)
var (
TooManyConns = ConnErr{ConnsExceeded, "too many connections"}
AuthRejected = ConnErr{BadAuth, "credentials rejected"}
)
var (
IllegalResponse = fmt.Errorf("illegal response")
IllegalHeader = fmt.Errorf("illegal headers")
)
type Client struct {
MaxConns, Port int
Server, User, Pass string
Tls bool
}
func NewClient(server string, port int) *Client
func (cli *Client) Auth(u, p string) error
func (cli *Client) Capabilities() ([]string, error)
func (cli *Client) Do(format string, args ...interface{}) (*Response, error)
func (cli *Client) GetArticle(group, id string) (res *Response, err error)
Client method GetArticle
func (cli *Client) Head(group, id string) (*Response, error)
func (cli *Client) JoinGroup(name string) error
func (cli *Client) List() ([]Group, error)
func (cli *Client) ListGroup(gid string) ([]string, error)
func (cli *Client) SetMaxConns(n int)
type Conn struct {
}
func NewConn(c io.ReadWriteCloser, wrappers ...func(io.Reader) io.Reader) *Conn
func (conn *Conn) Auth(u, p string) error
func (c *Conn) Close() error
func (c *Conn) Do(format string, is ...interface{}) (*Response, error)
func (c *Conn) Wrap(fn ...func(io.Reader) io.Reader)
type ConnErr struct {
Code int `json:"code"xml:"code"`
Reason string `json:"reason"xml:"reason"`
}
func (c ConnErr) Error() string
type Group struct {
Id string
Count, First int
}
type Reader struct {
R *bufio.Reader
}
A Reader is a read/closer that strips NNTP newlines and will unescape characters.
func NewReader(r io.Reader) *Reader
NewReader returns an nntp.Reader for the body of the nttp article.
func (r *Reader) Close() error
Close allows users of a Reader to signal that they are done using the reader.
func (r *Reader) Read(p []byte) (bytesRead int, err error)
The Read method handles translation of the NNTP escaping and marking EOF when the end of a body is received.
type Response struct {
Code int `json:"code"xml:"code"`
Message string `json:"message"xml:"message"`
Headers textproto.MIMEHeader `json:"headers"xml:"headers"`
Body io.ReadCloser `json:"body"xml:"body"` //Presence (non-nil) indicates multi-line response
}
func NewResponse(r io.Reader) (*Response, error)