operator

package
v1.0.0-rc2 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: MIT Imports: 6 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package operator defines the handler pipeline step model for httpx.

A route is a sequence of operators. [route.Handler] runs each step: unmarshal the request into a per-request instance, optional Initializer.Init, then Operator.Output. Non-final steps store [Output] in context for later steps; the final step's result is written as the HTTP response. Registration-time metadata and instance creation live in Factory. The public alias is [httpx.Operator].

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func TypeOfOperator

func TypeOfOperator(t reflect.Type) reflect.Type

TypeOfOperator returns the struct type for an operator, unwrapping pointers.

Types

type BasePathDescriber

type BasePathDescriber interface {
	BasePath() string
}

BasePathDescriber reports a base path prefix for a route group.

type DefaultSetter

type DefaultSetter interface {
	SetDefault()
}

DefaultSetter runs after instance creation in Factory.New.

type EmptyOperator

type EmptyOperator struct{}

EmptyOperator is a no-op Output used as the embedded base for meta operators.

func (EmptyOperator) NoOutput

func (EmptyOperator) NoOutput()

func (EmptyOperator) Output

func (EmptyOperator) Output(context.Context) (any, error)

type Factory

type Factory struct {
	Type       reflect.Type
	ContextKey any
	NoOutput   bool
	Params     url.Values
	IsLast     bool
	Operator   Operator
}

Factory holds compile-time metadata for one pipeline step and creates per-request operators.

func NewFactory

func NewFactory(op Operator, last bool) *Factory

NewFactory builds registration metadata from a prototype operator. last is true when op is the final step in the route chain (its Output becomes the HTTP response).

func (*Factory) New

func (f *Factory) New() (op Operator)

New creates a request-scoped operator: Newer.New or reflect.New, then InitializerFrom and DefaultSetter when implemented.

func (*Factory) String

func (f *Factory) String() string

type HasContextKey

type HasContextKey interface {
	Operator
	ContextKey() any
}

HasContextKey overrides the context key used when a non-final step's Output is stored for downstream operators. The default is the operator struct type name.

type HasMiddlewares

type HasMiddlewares interface {
	Middlewares() []Operator
}

HasMiddlewares expands one router entry into multiple operators when building a [route.Router].

type HasParameters

type HasParameters interface {
	OperatorParameters() map[string][]string
}

HasParameters attaches static query parameters to Factory (for example client defaults).

type Initializer

type Initializer interface {
	Init(context.Context) error
}

Initializer runs after request unmarshaling and before Output on each request.

type InitializerFrom

type InitializerFrom interface {
	Operator
	InitFromOperator(Operator)
}

InitializerFrom copies or derives state from the registration prototype into the per-request instance inside Factory.New.

type MetaOperator

type MetaOperator struct {
	EmptyOperator
	// contains filtered or unexported fields
}

MetaOperator contributes path metadata and performs no business Output.

Example
op := BasePathOperator("/base")
fmt.Println(op.(BasePathDescriber).BasePath())
fmt.Println(op)

op = GroupOperator("/base/group")
fmt.Println(op.(PathDescriber).Path())
fmt.Println(op)
Output:
/base
base(/base)
/base/group
group(/base/group)

func (*MetaOperator) BasePath

func (g *MetaOperator) BasePath() string

func (*MetaOperator) Path

func (g *MetaOperator) Path() string

func (*MetaOperator) String

func (g *MetaOperator) String() string

type Newer

type Newer interface {
	Operator
	New() Operator
}

Newer replaces the default reflect.New instance factory in Factory.New.

type NoOutput

type NoOutput interface {
	Operator
	NoOutput()
}

NoOutput marks a step that does not produce a response body by itself. Factory sets NoOutput when the registered prototype implements this interface.

type Operator

type Operator interface {
	Output(context.Context) (any, error)
}

Operator is one step in a route pipeline. Output returns the value passed to the next step (via context) or, on the last step, the HTTP response body.

func BasePathOperator

func BasePathOperator(base string) Operator

BasePathOperator returns a meta operator that only contributes BasePath to route metadata.

func GroupOperator

func GroupOperator(group string) Operator

GroupOperator returns a meta operator that only contributes Path to route metadata.

type PathDescriber

type PathDescriber interface {
	Path() string
}

PathDescriber reports a path segment appended when building route metadata.

Jump to

Keyboard shortcuts

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