Documentation ¶
Index ¶
- func LimitListener(l net.Listener, n int) net.Listener
- func LimitListenerWithLog(l net.Listener, n int, lg Printer) net.Listener
- func TCPListener(address string, port int, options ...Option) (net.Listener, error)
- func WebsocketListener(lg Printer) (*WSListener, HandlerFunc)
- type HandlerFunc
- type Option
- type Printer
- type WSListener
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func LimitListener ¶
LimitListener returns a Listener based on l that accepts at most n simultaneous connections. It will panic if n is negative.
func LimitListenerWithLog ¶
LimitListenerWithLog returns a Listener based on l that accepts at most n simultaneous connections. It will panic if n is negative. If connections are dropped due to the maximum number of connections being exceeded, this will be logged to lg.
func TCPListener ¶
TCPListener returns a net.Listener listening over TCP on address:port.
func WebsocketListener ¶
func WebsocketListener(lg Printer) (*WSListener, HandlerFunc)
WebsocketListener returns a net.Listener listening over a websocket. Also returns the handler function that should be passed to your http server in order to promote incoming connections to websocket connections.
Types ¶
type HandlerFunc ¶
type HandlerFunc func(http.ResponseWriter, *http.Request)
HandlerFunc is a function that can be passed to http.ServMux.HandleFunc to handle a http request.
type Option ¶
type Option interface {
// contains filtered or unexported methods
}
Option sets options on a TCP listener.
func MaxNumConnections ¶
MaxNumConnections sets the maximum number of connections.
type Printer ¶
type Printer interface {
Printf(format string, v ...interface{})
}
Printer is the interface satisfied by the Printf method.
type WSListener ¶
type WSListener struct {
// contains filtered or unexported fields
}
WSListener provides a net.Listener.
func WebsocketListenAndServe ¶
func WebsocketListenAndServe(uri string, options ...Option) (*WSListener, func() error, error)
WebsocketListenAndServe creates and starts a http.Server listening for websocket connections as described by uri. Returns the net.Listener for this server. A shutdown function for the http.Server is returned as the second return value.
func (*WSListener) Accept ¶
func (l *WSListener) Accept() (net.Conn, error)
Accept waits for and returns the next connection to the listener.
func (*WSListener) Addr ¶
func (*WSListener) Addr() net.Addr
Addr returns a dummy address whose Network() and String() values are always "ws".
func (*WSListener) Close ¶
func (l *WSListener) Close() error
Close closes the listener. Any blocked Accept operations will be unblocked and return errors. Already Accepted connections are not closed.
func (*WSListener) CloseWithErr ¶
func (l *WSListener) CloseWithErr(err error) error
CloseWithErr closes the listener as per Close, setting any error err to be returned.