nntpserver

package
v0.0.0-...-af2aeec Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2022 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package nntpserver provides everything you need for your own NNTP server.

Index

Constants

This section is empty.

Variables

View Source
var ErrAuthRejected = &NNTPError{452, "authorization rejected"}

ErrAuthRejected is returned for invalid authentication.

View Source
var ErrAuthRequired = &NNTPError{450, "authorization required"}

ErrAuthRequired is returned to indicate authentication is required to proceed.

View Source
var ErrInvalidArticleNumber = &NNTPError{423, "No article with that number"}

ErrInvalidArticleNumber is returned when an article is requested that can't be found.

View Source
var ErrInvalidMessageID = &NNTPError{430, "No article with that message-id"}

ErrInvalidMessageID is returned when a message is requested that can't be found.

View Source
var ErrNoCurrentArticle = &NNTPError{420, "Current article number is invalid"}

ErrNoCurrentArticle is returned when a command is executed that requires a current article when one has not been selected.

View Source
var ErrNoGroupSelected = &NNTPError{412, "No newsgroup selected"}

ErrNoSuchGroup is returned for a request that requires a current group when none has been selected.

View Source
var ErrNoSuchGroup = &NNTPError{411, "No such newsgroup"}

ErrNoSuchGroup is returned for a request for a group that can't be found.

View Source
var ErrNotAuthenticated = &NNTPError{480, "authentication required"}

ErrNotAuthenticated is returned when a command is issued that requires authentication, but authentication was not provided.

View Source
var ErrNotWanted = &NNTPError{435, "Article not wanted"}

ErrNotWanted is returned when an attempt to post an article is rejected due the server not wanting the article.

View Source
var ErrPostingFailed = &NNTPError{441, "posting failed"}

ErrPostingFailed is returned when an attempt to post an article fails.

View Source
var ErrPostingNotPermitted = &NNTPError{440, "Posting not permitted"}

ErrPostingNotPermitted is returned as the response to an attempt to post an article where posting is not permitted.

View Source
var ErrSyntax = &NNTPError{501, "not supported, or syntax error"}

ErrSyntax is returned when a command can't be parsed.

View Source
var ErrUnknownCommand = &NNTPError{500, "Unknown command"}

ErrUnknownCommand is returned for unknown comands.

Functions

This section is empty.

Types

type Backend

type Backend interface {
	ListGroups(ctx context.Context, max int) ([]*nntp.Group, error)
	GetGroup(ctx context.Context, name string) (*nntp.Group, error)
	GetArticle(ctx context.Context, group *nntp.Group, id string) (*nntp.Article, error)
	GetArticles(ctx context.Context, group *nntp.Group, from, to int64) ([]NumberedArticle, error)
	Authorized(ctx context.Context) bool
	// Authenticate and optionally swap out the backend for this Session.
	// You may return nil to continue using the same backend.
	Authenticate(ctx context.Context, user, pass string) (Backend, error)
	AllowPost(ctx context.Context) bool
	Post(ctx context.Context, article *nntp.Article) error
}

The Backend that provides the things and does the stuff.

type ContextKey

type ContextKey int
const (
	ContextKeyCommand ContextKey = iota
)

type Handler

type Handler func(ctx context.Context, args []string, s *Session, c *textproto.Conn) error

Handler is a low-level protocol handler

type MiddlewareFunc

type MiddlewareFunc func(Handler) Handler

func (MiddlewareFunc) Middleware

func (mw MiddlewareFunc) Middleware(handler Handler) Handler

type NNTPError

type NNTPError struct {
	Code int
	Msg  string
}

An NNTPError is a coded NNTP error message.

func (*NNTPError) Error

func (e *NNTPError) Error() string

type NumberedArticle

type NumberedArticle struct {
	Num     int64
	Article *nntp.Article
}

A NumberedArticle provides local sequence nubers to articles When listing articles in a group.

type Server

type Server struct {
	// Handlers are dispatched by command name.
	Handlers map[string]Handler
	// The backend (your code) that provides data
	Backend Backend
	// contains filtered or unexported fields
}

The Server handle.

func NewServer

func NewServer(backend Backend) *Server

NewServer builds a new server handle request to a backend.

func (*Server) Process

func (s *Server) Process(nc net.Conn)

Process an NNTP Session.

func (*Server) Use

func (s *Server) Use(mwf ...MiddlewareFunc)

type Session

type Session struct {
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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