handler

package
v0.5.0-dev Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2026 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EchoHandler

type EchoHandler struct{}

func (EchoHandler) HandleTCP

func (EchoHandler) HandleTCP(_ context.Context, conn net.Conn, env Env) error

func (EchoHandler) HandleUDP

func (EchoHandler) HandleUDP(_ context.Context, data []byte, _ net.Addr, env Env) ([]byte, error)

type Env

type Env struct {
	Logger      *slog.Logger
	Capture     *capture.Writer
	IdleTimeout time.Duration // connection idle timeout, used by conn:sleep
	Global      *state.Store
}

type Handler

type Handler interface {
	// HandleTCP serves a single accepted connection until it is closed.
	HandleTCP(ctx context.Context, conn net.Conn, env Env) error

	// HandleUDP processes a single datagram and returns an optional reply.
	HandleUDP(ctx context.Context, data []byte, remote net.Addr, env Env) ([]byte, error)
}

Handler processes network traffic for a listener.

func New

func New(spec string, baseDir string, budget *state.Budget) (Handler, error)

New resolves a handler spec. Supported forms:

builtin:echo - echo all received data back
builtin:sink - consume and discard all received data
lua:<path>   - serve with a Lua script (relative paths resolve against baseDir)

A nil budget gives the handler its own private state budget

type LuaHandler

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

func NewLua

func NewLua(path string, budget *state.Budget) (*LuaHandler, error)

func (*LuaHandler) HandleTCP

func (h *LuaHandler) HandleTCP(ctx context.Context, conn net.Conn, env Env) error

func (*LuaHandler) HandleUDP

func (h *LuaHandler) HandleUDP(_ context.Context, data []byte, remote net.Addr, env Env) ([]byte, error)

type SinkHandler

type SinkHandler struct{}

SinkHandler consumes and discards all received data.

func (SinkHandler) HandleTCP

func (SinkHandler) HandleTCP(_ context.Context, conn net.Conn, env Env) error

func (SinkHandler) HandleUDP

func (SinkHandler) HandleUDP(_ context.Context, data []byte, _ net.Addr, env Env) ([]byte, error)

Jump to

Keyboard shortcuts

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