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) Stop

func (cp *ConnectionPool) Stop()

Stop connection pool

type Operation

type Operation uint8

Operation defines what kind of operation to perform for provided article on the connection

const (
	// CHECK Operation
	// Check if article exists
	CHECK Operation = iota

	// FETCH Operation
	// Perform Fetch Operation for article
	FETCH
)

func (Operation) String

func (i Operation) String() string

type PoolConn

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

PoolConn represents a connection to a NNTP server within a connection pool

type Request

type Request struct {
	Article *Article  // Article Information
	Command Operation // Command Operation to perform
}

Request on connection

func NewRequest

func NewRequest(id string, groups []string, oper Operation) *Request

NewRequest create new request for connection

type Response

type Response struct {
	Article  *Article
	Commmand Operation // Operation which was executed
	Error    error     // Error of operation if any
	Source   string    // source of response HOST:PORT of connection
}

Response of work on connection

type ServerAuth

type ServerAuth struct {
	Username string
	Password string
}

ServerAuth authentication info for ServerInfo

type ServerInfo

type ServerInfo struct {
	Host string
	Port uint16
	TLS  bool
	Auth *ServerAuth
}

ServerInfo for nntp connection

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL