Documentation ¶
Index ¶
- Variables
- func MockCloser(id string)
- func MockEstablisher(id string, c net.Conn) error
- type CloseFn
- type Config
- type EstablishFn
- type HTTPHealthCheck
- type HTTPStats
- type Handler
- type Listener
- type Listeners
- func (l *Listeners) Add(val Listener)
- func (l *Listeners) Close(id string, closer CloseFn)
- func (l *Listeners) CloseAll(closer CloseFn)
- func (l *Listeners) Delete(id string)
- func (l *Listeners) Get(id string) (Listener, bool)
- func (l *Listeners) Len() int
- func (l *Listeners) Serve(id string, establisher EstablishFn)
- func (l *Listeners) ServeAll(establisher EstablishFn)
- type MockListener
- func (l *MockListener) Address() string
- func (l *MockListener) Close(closer CloseFn)
- func (l *MockListener) ID() string
- func (l *MockListener) Init(log *slog.Logger) error
- func (l *MockListener) IsListening() bool
- func (l *MockListener) IsServing() bool
- func (l *MockListener) Protocol() string
- func (l *MockListener) Serve(establisher EstablishFn)
- type Net
- type TCP
- type UnixSock
- type Websocket
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalidMessage indicates that a message payload was not valid. ErrInvalidMessage = errors.New("message type not binary") )
Functions ¶
func MockCloser ¶
func MockCloser(id string)
MockCloser is a function signature which can be used in testing.
Types ¶
type CloseFn ¶
type CloseFn func(id string)
CloseFn is a callback function for closing all listener clients.
type Config ¶
type Config struct { // TLSConfig is a tls.Config configuration to be used with the listener. // See examples folder for basic and mutual-tls use. TLSConfig *tls.Config }
Config contains configuration values for a listener.
type EstablishFn ¶
EstablishFn is a callback function for establishing new clients.
type HTTPHealthCheck ¶ added in v2.5.0
HTTPHealthCheck is a listener for providing an HTTP healthcheck endpoint.
func NewHTTPHealthCheck ¶ added in v2.5.0
func NewHTTPHealthCheck(id, address string, config *Config) *HTTPHealthCheck
NewHTTPHealthCheck initialises and returns a new HTTP listener, listening on an address.
func (*HTTPHealthCheck) Address ¶ added in v2.5.0
func (l *HTTPHealthCheck) Address() string
Address returns the address of the listener.
func (*HTTPHealthCheck) Close ¶ added in v2.5.0
func (l *HTTPHealthCheck) Close(closeClients CloseFn)
Close closes the listener and any client connections.
func (*HTTPHealthCheck) ID ¶ added in v2.5.0
func (l *HTTPHealthCheck) ID() string
ID returns the id of the listener.
func (*HTTPHealthCheck) Init ¶ added in v2.5.0
func (l *HTTPHealthCheck) Init(_ *slog.Logger) error
Init initializes the listener.
func (*HTTPHealthCheck) Protocol ¶ added in v2.5.0
func (l *HTTPHealthCheck) Protocol() string
Protocol returns the address of the listener.
func (*HTTPHealthCheck) Serve ¶ added in v2.5.0
func (l *HTTPHealthCheck) Serve(establish EstablishFn)
Serve starts listening for new connections and serving responses.
type HTTPStats ¶
HTTPStats is a listener for presenting the server $SYS stats on a JSON http endpoint.
func NewHTTPStats ¶
NewHTTPStats initialises and returns a new HTTP listener, listening on an address.
func (*HTTPStats) Serve ¶
func (l *HTTPStats) Serve(establish EstablishFn)
Serve starts listening for new connections and serving responses.
type Listener ¶
type Listener interface { Init(*slog.Logger) error // open the network address Serve(EstablishFn) // starting actively listening for new connections ID() string // return the id of the listener Address() string // the address of the listener Protocol() string // the protocol in use by the listener Close(CloseFn) // stop and close the listener }
Listener is an interface for network listeners. A network listener listens for incoming client connections and adds them to the server.
type Listeners ¶
Listeners contains the network listeners for the broker.
func (*Listeners) Serve ¶
func (l *Listeners) Serve(id string, establisher EstablishFn)
Serve starts a listener serving from the internal map.
func (*Listeners) ServeAll ¶
func (l *Listeners) ServeAll(establisher EstablishFn)
ServeAll starts all listeners serving from the internal map.
type MockListener ¶
type MockListener struct { sync.RWMutex Config *Config // configuration for the listener Serving bool // indicate the listener is serving Listening bool // indiciate the listener is listening ErrListen bool // throw an error on listen // contains filtered or unexported fields }
MockListener is a mock listener for establishing client connections.
func NewMockListener ¶
func NewMockListener(id, address string) *MockListener
NewMockListener returns a new instance of MockListener.
func (*MockListener) Address ¶
func (l *MockListener) Address() string
Address returns the address of the listener.
func (*MockListener) Close ¶
func (l *MockListener) Close(closer CloseFn)
Close closes the mock listener.
func (*MockListener) ID ¶
func (l *MockListener) ID() string
ID returns the id of the mock listener.
func (*MockListener) Init ¶
func (l *MockListener) Init(log *slog.Logger) error
Init initializes the listener.
func (*MockListener) IsListening ¶
func (l *MockListener) IsListening() bool
IsListening indicates whether the mock listener is listening.
func (*MockListener) IsServing ¶
func (l *MockListener) IsServing() bool
IsServing indicates whether the mock listener is serving.
func (*MockListener) Protocol ¶
func (l *MockListener) Protocol() string
Protocol returns the address of the listener.
func (*MockListener) Serve ¶
func (l *MockListener) Serve(establisher EstablishFn)
Serve serves the mock listener.
type Net ¶ added in v2.5.0
type Net struct {
// contains filtered or unexported fields
}
Net is a listener for establishing client connections on basic TCP protocol.
func NewNet ¶ added in v2.5.0
NewNet initialises and returns a listener serving incoming connections on the given net.Listener
func (*Net) Serve ¶ added in v2.5.0
func (l *Net) Serve(establish EstablishFn)
Serve starts waiting for new TCP connections, and calls the establish connection callback for any received.
type TCP ¶
TCP is a listener for establishing client connections on basic TCP protocol.
func (*TCP) Serve ¶
func (l *TCP) Serve(establish EstablishFn)
Serve starts waiting for new TCP connections, and calls the establish connection callback for any received.
type UnixSock ¶
UnixSock is a listener for establishing client connections on basic UnixSock protocol.
func NewUnixSock ¶
NewUnixSock initialises and returns a new UnixSock listener, listening on an address.
func (*UnixSock) Serve ¶
func (l *UnixSock) Serve(establish EstablishFn)
Serve starts waiting for new UnixSock connections, and calls the establish connection callback for any received.
type Websocket ¶
Websocket is a listener for establishing websocket connections.
func NewWebsocket ¶
NewWebsocket initialises and returns a new Websocket listener, listening on an address.
func (*Websocket) Serve ¶
func (l *Websocket) Serve(establish EstablishFn)
Serve starts waiting for new Websocket connections, and calls the connection establishment callback for any received.