handler

package module
v0.0.0-...-7a2ca8f Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2025 License: MIT Imports: 7 Imported by: 4

README

handler-go

Go Reference GoReportCard codecov

handler-go provides the connection handler for the cmd-stream server.

It implements the server.TransportHandler interface from the delegate-go module and executes each command in its own goroutine using the Invoker.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Apply

func Apply(ops []SetOption, o *Options)

Types

type Handler

type Handler[T any] struct {
	// contains filtered or unexported fields
}

Handler implements the delegate.ServerTransportHandler interface.

It receives Commands sequentially and executes each in a separate goroutine using the Invoker.

If an error occurs, the Handler closes the transport connection.

func New

func New[T any](invoker Invoker[T], ops ...SetOption) *Handler[T]

New creates a new Handler.

func (*Handler[T]) Handle

func (h *Handler[T]) Handle(ctx context.Context, transport dsrv.Transport[T]) (
	err error)

type Invoker

type Invoker[T any] interface {
	Invoke(ctx context.Context, seq core.Seq, at time.Time, bytesRead int,
		cmd core.Cmd[T], proxy core.Proxy) error
}

Invoker executes Commands on the server.

A single Invoker instance handles Commands concurrently in separate goroutines, so it must be thread-safe. The Invoke method can act as a central handler for common operations across multiple Commands, such as logging.

type InvokerFn

type InvokerFn[T any] func(ctx context.Context, seq core.Seq, at time.Time,
	bytesRead int, cmd core.Cmd[T], proxy core.Proxy) error

InvokerFn is a functional implementation of the Invoker interface.

func (InvokerFn[T]) Invoke

func (i InvokerFn[T]) Invoke(ctx context.Context, seq core.Seq, at time.Time,
	bytesRead int, cmd core.Cmd[T], proxy core.Proxy) error

type Options

type Options struct {
	CmdReceiveDuration time.Duration
	At                 bool
}

type Proxy

type Proxy[T any] struct {
	// contains filtered or unexported fields
}

Proxy implemets the core.Proxy interface.

func NewProxy

func NewProxy[T any](transport dsrv.Transport[T]) Proxy[T]

NewProxy creates a new Proxy.

func (Proxy[T]) LocalAddr

func (p Proxy[T]) LocalAddr() net.Addr

func (Proxy[T]) RemoteAddr

func (p Proxy[T]) RemoteAddr() net.Addr

func (Proxy[T]) Send

func (p Proxy[T]) Send(seq core.Seq, result core.Result) (n int, err error)

func (Proxy[T]) SendWithDeadline

func (p Proxy[T]) SendWithDeadline(seq core.Seq, result core.Result,
	deadline time.Time) (n int, err error)

type SetOption

type SetOption func(o *Options)

func WithAt

func WithAt() SetOption

WithAt enables the "at" flag. When enabled, the Handler passes the command's received timestamp to Invoker.Invoke().

func WithCmdReceiveDuration

func WithCmdReceiveDuration(d time.Duration) SetOption

WithCmdReceiveDuration sets the maximum time the Handler will wait for a command. If no command arrives within this duration, the connection is closed. A duration of 0 means the Handler will wait indefinitely.

Jump to

Keyboard shortcuts

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