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 ¶
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()
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 ¶
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 ¶
New creates a request-scoped operator: Newer.New or reflect.New, then InitializerFrom and DefaultSetter when implemented.
type HasContextKey ¶
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 ¶
HasParameters attaches static query parameters to Factory (for example client defaults).
type Initializer ¶
Initializer runs after request unmarshaling and before Output on each request.
type InitializerFrom ¶
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 ¶
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 ¶
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 ¶
BasePathOperator returns a meta operator that only contributes BasePath to route metadata.
func GroupOperator ¶
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.