Help us shape the future of Go! Take the 2026 Go Developer Survey

socketmap

package module
v0.0.0-...-46d6074 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2023 License: BSD-2-Clause Imports: 10 Imported by: 1

README

go-socketmap

Sendmail socketmap protocol server in pure go

Documentation

Overview

Package socketmap implements the Sendmail socketmap protocol

Index

Constants

View Source
const MaxSize = 100000

MaxSize is the maximum size of a socketmap message in bytes.

Variables

This section is empty.

Functions

func ListenAndServe

func ListenAndServe(network, addr string, handler Handler) error

ListenAndServe listens on the network address addr and then calls Serve with handler to handle requests on incoming connections.

ListenAndServe always returns a non-nil error.

func Serve

func Serve(l net.Listener, handler Handler) error

Serve accepts incoming socketmap connections on the listener l, creating a new service goroutine for each. The service goroutines read requests and then call handler to reply to them.

Serve always returns a non-nil error.

Types

type Client

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

func NewClient

func NewClient(network, addr string, opts ...ClientOption) *Client

NewClient returns a new Client that connects to a socketmap server with network and address. You can pass additional opts. The defaults are using maximum of 10 parallel connections and a net.Dialer with a 10 seconds timeout.

func (*Client) Close

func (c *Client) Close()

Close finishes all connections. Waits until all connections are closed. After the call to Close all LookupContext calls will return an error.

func (*Client) Lookup

func (c *Client) Lookup(lookup, key string) (string, bool, error)

Lookup calls LookupContext with context.Background as ctx.

func (*Client) LookupContext

func (c *Client) LookupContext(ctx context.Context, lookup, key string) (value string, ok bool, err error)

LookupContext lookup key in the lookup map of c. If ctx is Done while looking up key, err will be ctx.Err(). If the map has a value, ok will be true. If map does not have a value for key, value will be "" and ok will be false. If there is a communication error or the socketmap server returns an error, err will be non-nil.

type ClientOption

type ClientOption func(clientOptions)

func WithDialer

func WithDialer(dialer Dialer) ClientOption

func WithMaxSize

func WithMaxSize(maxSize int32) ClientOption

type Dialer

type Dialer interface {
	DialContext(ctx context.Context, network, addr string) (net.Conn, error)
}

type Handler

type Handler func(ctx context.Context, lookup, key string) (result string, found bool, err error)

A Handler responds to a Sendmail socketmap request. ctx is a context you can pass down to potentially long-running functions. lookup and key are the two parsed request variables (the map name and the map key to look up).

A Handler should return found = true when key was found in lookup. Then result holds the value associated with key. If the Handler returns a non-nil err this error gets passed back to the client. You can use PermanentError or TimeoutError to signal a permanent or timeout error to the client. All other errors are returned as temporary errors.

type PermanentError

type PermanentError struct {
	Reason string
}

func (PermanentError) Error

func (e PermanentError) Error() string

func (PermanentError) Temporary

func (PermanentError) Temporary() bool

func (PermanentError) Timeout

func (PermanentError) Timeout() bool

type TempError

type TempError struct {
	Reason string
}

func (TempError) Error

func (e TempError) Error() string

func (TempError) Temporary

func (TempError) Temporary() bool

func (TempError) Timeout

func (TempError) Timeout() bool

type TimeoutError

type TimeoutError struct {
	Reason string
}

func (TimeoutError) Error

func (e TimeoutError) Error() string

func (TimeoutError) Temporary

func (TimeoutError) Temporary() bool

func (TimeoutError) Timeout

func (TimeoutError) Timeout() bool

Directories

Path Synopsis
cmd
log-socketmap command
Command log-socketmap is a socketmap server that always returns NOTFOUND and logs all requests.
Command log-socketmap is a socketmap server that always returns NOTFOUND and logs all requests.
test-socketmap command
Command test-socketmap is a test client for a socketmap server
Command test-socketmap is a test client for a socketmap server

Jump to

Keyboard shortcuts

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