nntp

package module
v0.0.0-...-783723f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 25, 2016 License: MIT Imports: 6 Imported by: 2

README

NNTP

Golang NNTP Library with multi connection support

Install

go get github.com/GJRTimmer/nntp

Package Info

Conn Interface is primarly used for a single connection to a NNTP server.

type Conn interface {
    Connect() bool
    Close() error

    SwitchGroup(group string) error
    ArticleExists(id string) (bool, error)
    FetchArticle(id string) ([]byte, error)
}

PoolConn is a connection used within a connection pool for multi connection to a NNTP server. PoolConn inherit Conn.

type PoolConn interface {
    Conn
    Start()
    Stop()
    ResponseChannel() chan *Response
}

Usage

For both single and multi user connection, details of the NNTP server must be provided.

ServerInfo Structure
  • Host string
  • Port uint16 Port number 0-65536
  • TLS bool Boolean to use TLS for connection
  • Auth ServerAuth If Auth == nil no authentication is preformed by the library
    • Username string
    • Password string
// ServerInfo for nntp connection
type ServerInfo struct {
    Host        string
    Port        uint16
    TLS         bool
    Auth        *ServerAuth
}

// ServerAuth authentication info for ServerInfo
type ServerAuth struct {
    Username    string
    Password    string
}
Example Server Info
    sInfo := &nntp.ServerInfo {
        Host: "<HOST>",
        Port: <PORT>, // if port variable != uint16, don't forget to cast uint16(port)
        TLS: true,
        Auth: &nntp.ServerAuth {
            Username: "<USERNAME>",
            Password: "<PASSWORD>",
        },
    }
Usage Single Connection
Usage Multi Connection

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Article

type Article struct {
	ID     string   // Article ID
	Groups []string // Groups which holds the article

	// Result
	Exists  bool   // Flag which defines if article exists on NNTP server
	Content []byte // Content of fetched article, filled on operation fetch, otherwise NIL
}

Article describes the article information

func (*Article) String

func (a *Article) String() string

type Conn

type Conn interface {
	Connect() (bool, error)
	Close() error

	SwitchGroup(group string) error
	ArticleExists(id string) (bool, error)
	FetchArticle(id string) ([]byte, error)
}

Conn represent(s) a single connection to a NNTP Server

func NewConn

func NewConn(id int, i *ServerInfo) Conn

NewConn create a new NNTP connection based on provided ServerInfo

type ConnectionPool

type ConnectionPool struct {
	Info *ServerInfo
	// contains filtered or unexported fields
}

ConnectionPool to NNTP server

func NewConnectionPool

func NewConnectionPool(i *ServerInfo, reqQueue chan *Request, maxConnections int) *ConnectionPool

NewConnectionPool create new connection pool to NNTP Server

func (*ConnectionPool) Collect

func (cp *ConnectionPool) Collect() chan *Response

Collect *Response(s) from ConnectionPool

func (*ConnectionPool) Start

func (cp *ConnectionPool) Start()

Start connection pool

func (*ConnectionPool)