types

package
v1.6.1 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2023 License: Unlicense Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Handler

type Handler interface {
	Handle(context.Context, *Request) *Response
}

Handler is a type which can turn a request into a response.

Handle may return a nil response, in which case the Server is expected to build the protocol-appropriate "Not Found" response.

func HandlerFunc

func HandlerFunc(f func(context.Context, *Request) *Response) Handler

type Middleware

type Middleware func(Handler) Handler

Middleware is a handler decorator.

It returns a handler which may call the passed-in handler or not, or may transform the request or response in some way.

type Request

type Request struct {
	// URL is the specific URL being fetched by the request.
	*url.URL

	// Server is the server which received the request.
	//
	// This is only populated in servers.
	// It is unused on the client end.
	Server Server

	// Meta is a place for opaque data.
	//
	// Look for helper methods in protocol packages to use it appropriately
	// for the protocol.
	Meta any

	// RemoteAddr is the address of the other side of the connection.
	//
	// This will be the server address for clients, or the connecting
	// client's address in servers.
	//
	// Be aware though that proxies (and reverse proxies) can confuse this.
	RemoteAddr net.Addr

	// TLSState contains information about the TLS encryption over the connection.
	//
	// This includes peer certificates and version information.
	TLSState *tls.ConnectionState
}

Request represents a request over any small web protocol.

Because protocols have so many differences, this type represents a greatest common denominator of request/response-oriented protocols.

func (Request) UnescapedQuery

func (req Request) UnescapedQuery() string

UnescapedQuery performs %XX unescaping on the URL query segment.

Like URL.Query(), it silently drops malformed %-encoded sequences.

type Response

type Response struct {
	// Status is the status code of the response.
	Status Status

	// Meta contains status-specific additional information.
	Meta any

	// Body is the response body, if any.
	Body io.Reader
}

Response contains the data in a response over the small web.

Because protocols have so many differences, this type represents a greatest common denominator of request/response-oriented protocols.

func (*Response) Close

func (response *Response) Close() error

type ResponseReader

type ResponseReader interface {
	io.Reader
	io.WriterTo
	io.Closer
}

ResponseReader is an object which can serialize a response to a protocol.

type Server

type Server interface {
	// Serve blocks listening for connections on an interface.
	//
	// It will only return after Close() has been called.
	Serve() error

	// Close initiates a graceful shutdown of the server.
	//
	// It blocks until all resources have been cleaned up and all
	// outstanding requests have been handled and responses sent.
	Close()

	// Closed indicates whether Close has been called.
	//
	// It may be true even if the graceful shutdown procedure
	// hasn't yet completed.
	Closed() bool

	// Protocol returns the protocol being served by the server.
	Protocol() string

	// Network returns the network type on which the server is running.
	Network() string

	// Address returns the address on which the server is listening.
	Address() string

	// Hostname returns just the hostname portion of the listen address.
	Hostname() string

	// Port returns the port on which the server is listening.
	//
	// It will return the empty string if the network type does not
	// have ports (unix sockets, for example).
	Port() string

	// LogError sends a log message to the server's error log.
	LogError(keyvals ...any) error
}

Server is a type which can serve a protocol.

type ServerProtocol added in v1.6.0

type ServerProtocol interface {
	TemporaryRedirect(*url.URL) *Response
	PermanentRedirect(*url.URL) *Response

	TemporaryServerError(error) *Response
	PermanentServerError(error) *Response
	CGIFailure(error) *Response

	Success(filename string, body io.Reader) *Response

	ParseResponse(io.Reader) (*Response, error)
}

type Status

type Status int

Status is the integer status code of a response.

Jump to

Keyboard shortcuts

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