Documentation
¶
Overview ¶
Package netx provides a TCP server that runs a Handler per connection, plus connection middleware and wrappers.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Handler ¶
func LoggingHandler ¶ added in v1.26.0
LoggingHandler records the conversation; next gets the recorder via LoggingConnFromContext.
func MaxBytesHandler ¶ added in v1.26.0
MaxBytesHandler limits the total number of bytes read from the connection.
func RateLimitHandler ¶ added in v1.26.0
RateLimitHandler drops connections for which allow returns false.
type HandlerFunc ¶
type LoggingConn ¶
type LoggingConn struct {
net.Conn
// Data is the ordered conversation log: each Read/Write call appends one
// message, so reads and writes are interleaved in call order.
Data [][]byte
// onClose is called when connection is closed.
// Must be used to get final conversation log.
OnClose func()
// contains filtered or unexported fields
}
LoggingConn wraps net.Conn to save conversation log.
func LoggingConnFromContext ¶ added in v1.26.0
func LoggingConnFromContext(ctx context.Context) *LoggingConn
LoggingConnFromContext returns the recorder set by LoggingHandler, or nil.
func NewLoggingConn ¶
func NewLoggingConn(conn net.Conn) *LoggingConn
NewLoggingConn wraps net.Conn and adds logging.
func (*LoggingConn) Close ¶
func (c *LoggingConn) Close() error
Close overwrites net.Conn Close method to call onClose function.
func (*LoggingConn) Read ¶
func (c *LoggingConn) Read(b []byte) (int, error)
Read overwrites net.Conn Read method to be able to save data to log.
func (*LoggingConn) Upgrade ¶ added in v1.26.0
func (c *LoggingConn) Upgrade(conn net.Conn)
Upgrade replaces the underlying connection, e.g. with TLS on top of it, keeping the log.
type LoggingListener ¶
LoggingListener is net.Listener wrapper that returns wraps net.Conn with LoggingConn.
type MaxBytesConn ¶
type Option ¶ added in v1.26.0
type Option func(*options)
func WithNotifyStarted ¶ added in v1.26.0
func WithNotifyStarted(f func()) Option
WithNotifyStarted sets a function called once the server is listening.
func WithTLSConfig ¶ added in v1.26.0
WithTLSConfig makes the server accept TLS connections.
type RateLimitListener ¶ added in v1.26.0
RateLimitListener closes accepted connections for which Allow returns false.