Documentation
¶
Overview ¶
Package socket provides a server and client for creating and using sessions over a socket.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a low-level client for reading and writing to a socket.
type HandlerFunc ¶
HandlerFunc is an adapter to allow the use of ordinary functions as socket handlers.
func (HandlerFunc) ServeSocket ¶
func (f HandlerFunc) ServeSocket(ctx context.Context, s Socket)
ServeSocket calls f(ctx, s)
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
func NewServer ¶
func NewServer(address string, handler Handler, options ...ServerOption) *Server
NewServer creates and returns a new socket server.
type ServerOption ¶
type ServerOption func(*Server)
func WithLogger ¶
func WithLogger(logger *slog.Logger) ServerOption
WithLogger sets logger on the server.
func WithTimeout ¶
func WithTimeout(timeout time.Duration) ServerOption
WithTimeout sets the timeout for all connections.
type Socket ¶
type Socket interface {
io.ReadWriter
// Deadline returns the configured deadline
// on the socket.
Deadline() time.Time
// SetDeadline sets the read and write deadlines associated with the connection.
// It is equivalent to calling both SetReadDeadline and SetWriteDeadline.
SetDeadline(t time.Time) error
}
Socket wraps around io.ReadWriter and SetDeadline. The internal handler is responsible for closing the socket (connection).
Click to show internal directories.
Click to hide internal directories.