thwack

package
v0.0.16 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2023 License: AGPL-3.0 Imports: 7 Imported by: 6

Documentation

Overview

Package thwack provides a trivial text based management protocol.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CommandHandlerFn

type CommandHandlerFn func(*Conn, string) error

CommandHandlerFn is a command handler hook function. Each handler function is responsible for fully handling a command and sending a response, and MUST NOT return an error unless the connection is to be closed immediately.

type Config

type Config struct {
	// Net and Addr specify the network and address of the server instance.
	Net, Addr string

	// ServiceName is the service name to be displayed in the greeting banner.
	ServiceName string

	// LogModule is the module for the Server's Logger.
	LogModule string

	// NewLoggerFn is the function to call to construct per-connection Loggers.
	NewLoggerFn func(string) *logging.Logger
}

Config is a thwack Server configuration.

type Conn

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

Conn is a thwack connection instance.

func (*Conn) Log

func (c *Conn) Log() *logging.Logger

Log returns the per-connection logging.Logger.

func (*Conn) Reader

func (c *Conn) Reader() *textproto.Reader

Reader returns the underlying textproto.Reader.

func (*Conn) SetState

func (c *Conn) SetState(state interface{})

SetState sets the per-connection state.

func (*Conn) State

func (c *Conn) State() interface{}

State returns the per-connection state.

func (*Conn) WriteReply

func (c *Conn) WriteReply(status StatusCode) error

WriteReply is a convenience routine for sending a StatusCode and human readable reason to the peer.

func (*Conn) Writer

func (c *Conn) Writer() *textproto.Writer

Writer returns the underlying textproto.Writer.

type Server

type Server struct {
	sync.WaitGroup
	// contains filtered or unexported fields
}

Server is a thwack server instance.

func New

func New(cfg *Config) (*Server, error)

New constructs a new Server, but does not start the listener.

func (*Server) Halt

func (s *Server) Halt()

Halt halts the Server.

func (*Server) RegisterCommand

func (s *Server) RegisterCommand(cmd string, fn CommandHandlerFn)

RegisterCommand sets the handler function for the specified command. This MUST NOT be called after the Server has been started with Start().

func (*Server) Start

func (s *Server) Start() error

Start starts the Server's listener and starts accepting connections.

type StatusCode

type StatusCode int

StatusCode is a thwack status code.

const (
	// StatusServiceReady is the status code that is always sent on a new
	// connection to signify that the management interface is ready.
	StatusServiceReady StatusCode = 220

	// StatusOk is the status code returned to signal successful completion
	// of a command.
	StatusOk StatusCode = 250

	// StatusUnknownCommand is the status code returned when a command is
	// unknown.
	StatusUnknownCommand StatusCode = 500

	// StatusSyntaxError is the status code returned when the syntax of a
	// command or it's argument(s) is invalid.
	StatusSyntaxError StatusCode = 501

	// StatusTransactionFailed is the status code returned when the command
	// has failed.
	StatusTransactionFailed StatusCode = 554
)

Jump to

Keyboard shortcuts

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