textproto

package
v0.9.9 Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package textproto implements generic support for text-based request/response protocols in the style of HTTP, NNTP, and SMTP.

The package provides:

Error, which represents a numeric error response from a server.

Pipeline, to manage pipelined requests and responses in a client.

Reader, to read numeric response code lines, key: value headers, lines wrapped with leading spaces on continuation lines, and whole text blocks ending with a dot on a line by itself.

Writer, to write dot-encoded text blocks.

Conn, a convenient packaging of Reader, Writer, and Pipeline for use with a single network connection.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func TrimBytes

func TrimBytes(b []byte) []byte

TrimBytes returns b without leading and trailing ASCII space.

func TrimString

func TrimString(s string) string

TrimString returns s without leading and trailing ASCII space.

Types

type Conn

type Conn struct {
	Reader
	Writer
	Pipeline
	// contains filtered or unexported fields
}

A Conn represents a textual network protocol connection. It consists of a Reader and Writer to manage I/O and a Pipeline to sequence concurrent requests on the connection. These embedded types carry methods with them; see the documentation of those types for details.

func Dial

func Dial(network, addr string) (*Conn, error)

Dial connects to the given address on the given network using net.Dial and then returns a new Conn for the connection.

func NewConn

func NewConn(conn io.ReadWriteCloser) *Conn

NewConn returns a new Conn using conn for I/O.

func (*Conn) Close

func (c *Conn) Close() error

Close closes the connection.

func (*Conn) Cmd

func (c *Conn) Cmd(format string, args ...any) (id uint, err error)

Cmd is a convenience method that sends a command after waiting its turn in the pipeline. The command text is the result of formatting format with args and appending \r\n. Cmd returns the id of the command, for use with StartResponse and EndResponse.

For example, a client might run a HELP command that returns a dot-body by using:

id, err := c.Cmd("HELP")
if err != nil {
	return nil, err
}

c.StartResponse(id)
defer c.EndResponse(id)

if _, _, err = c.ReadCodeLine(110); err != nil {
	return nil, err
}
text, err := c.ReadDotBytes()
if err != nil {
	return nil, err
}
return c.ReadCodeLine(250)

type Error

type Error struct {
	Code int
	Msg  string
}

An Error represents a numeric error response from a server.

func (*Error) Error

func (e *Error) Error() string

type ProtocolError

type ProtocolError string

A ProtocolError describes a protocol violation such as an invalid response or a hung-up connection.

func (ProtocolError) Error

func (p ProtocolError) Error() string

Jump to

Keyboard shortcuts

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