nntpPool

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2024 License: MIT Imports: 7 Imported by: 0

README

nntpPool.go

An NNTP connection pool package for go (golang) using Tensai75/nntp for the NNTP connections.

Example

	initialConnections := uint32(10)

	// create a pool
	pool, err := nntpPool.New(&nntpPool.Config{
		Name:                  "Newshosting",
		Host:                  "news.newshosting.com",
		Port:                  119,
		SSL:                   false,
		SkipSSLCheck:          true,
		User:                  "username",
		Pass:                  "password",
		MaxConns:              50,
		ConnWaitTime:          10,
		IdleTimeout:           30,
		HealthCheck:           true,
		MaxTooManyConnsErrors: 3,
		MaxConnErrors:         3,
	}, initialConnections)
	if err != nil {
		log.Fatal("unable to create the connection pool")
	}

	// get a connection from the pool
	conn, err := pool.Get(context.TODO())
	if err != nil {
		log.Fatal("unable to get a connection from the pool")
	}

	// return the connection to the pool
	pool.Put(conn)

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// message channels
	WarnChan  = make(chan error, 10)  // warning messages (errors which did not cause the pool to fail)
	LogChan   = make(chan string, 10) // informative messages
	DebugChan = make(chan string, 10) // additional debug messages
)

Functions

This section is empty.

Types

type Config

type Config struct {
	// Name for the usenet server
	Name string
	// Usenet server host name or IP address
	Host string
	// Usenet server port number
	Port uint32
	// Use SSL if set to true
	SSL bool
	// Skip SSL certificate check
	SkipSSLCheck bool
	// Username to connect to the usenet server
	User string
	// Password to connect to the usenet server
	Pass string
	// Max number of opened connections.
	MaxConns uint32
	// Time to wait in seconds before trying to re-connect
	ConnWaitTime time.Duration
	// Duartion after idle connections will be closed
	IdleTimeout time.Duration
	// Check health of connection befor passing it on
	HealthCheck bool
	// Number of max "too many connections" errors after which MaxConns is automatically reduced (0 = disabled)
	MaxTooManyConnsErrors uint32
	// Number of max consecutive connection errors after which the pool fails if no connection could be established at all (0 = disabled)
	MaxConnErrors uint32
}

type ConnectionPool

type ConnectionPool interface {
	// Returns number of currently used and total opened connections.
	Conns() (uint32, uint32)
	// Returns the maximum number of simultaneously used connections.
	MaxConns() uint32
	// Retrieves connection from pool if it exists or opens new connection.
	Get(ctx context.Context) (*NNTPConn, error)
	// Returns connection to pool.
	Put(conn *NNTPConn)
	// Closes all connections and pool.
	Close()
}

func New

func New(cfg *Config, initialConns uint32) (ConnectionPool, error)

Opens new connection pool.

type NNTPConn

type NNTPConn struct {
	*nntp.Conn
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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