Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Handle

func Handle(server *Server, conn net.Conn)

Given a `dict.Server` and a `net.Conn`, do a bringup, and run the * `ReadLine` loop, dispatching commands to the correct internals.

func WriteCode

func WriteCode(session *Session, code int, message string)

Helper for commands to write out a code line

func WriteTextBlock

func WriteTextBlock(session *Session, stream string)

Helper for commands to write out a text block

Types

type Command

type Command struct {
	Command string
	Params  []string
}

Command is the encapsulation for a user's request of the Server.

type Database

type Database interface {

	/* Method to handle incoming `MATCH` commands. */
	Match(name string, query string, strat string) []*Definition

	/* Method to handle incoming `DEFINE` commands. */
	Define(name string, query string) []*Definition

	/* Method to handle incoming `SHOW INFO` commands. */
	Info(name string) string

	/* Method to return a one-line Description of the Database. */
	Description(name string) string

	/* Get a list of valid Match Strategies. */
	Strategies(name string) map[string]string
}

Database is an interface for external Database "Backends" to implement.

type Definition

type Definition struct {
	Word             string
	Definition       string
	DictDatabase     Database
	DictDatabaseName string
}

Definition is the encapsulation of a response for a given Entry.

type Server

type Server struct {
	Name string
	Info string
	// contains filtered or unexported fields
}

Server encapsulation. * * This contains a bundle of useful helpers, as well as a few data structures * to handle registered Databases and Commands.

func NewServer

func NewServer(name string) Server

Create a new server by name `name`.

func (*Server) Define

func (this *Server) Define(
	database string,
	query string,
) ([]*Definition, error)

Define a word against the server, according to fun rules!

func (*Server) GetDatabase

func (this *Server) GetDatabase(name string) Database

Get dict.Database that has been registered under `name`.

func (*Server) GetHandler

func (this *Server) GetHandler(command *Command) func(*Session, Command)

Get a Command handler for the given dict.Command `command`

func (*Server) Match

func (this *Server) Match(
	database string,
	query string,
	strat string,
) ([]*Definition, error)

Define a word against the server, according to fun rules!

func (*Server) RegisterDatabase

func (this *Server) RegisterDatabase(database Database, name string, all bool)

Register dict.Database `database` under `name`.

func (*Server) RegisterHandler

func (this *Server) RegisterHandler(
	name string,
	handler func(*Session, Command),
)

Register a Command `handler` under name `name`.

type Session

type Session struct {
	MsgId      string
	Client     string
	Connection *textproto.Conn
	DictServer *Server
	Options    map[string]bool
}

Session contains state data that lasts throughout the connection.