Documentation
¶
Overview ¶
Package middleware provides route grouping and middleware management for the neoma framework, allowing shared path prefixes, middleware chains, and operation modifiers to be applied to groups of routes.
Index ¶
- func Build(builder Builder, op *core.Operation) core.MiddlewareFunc
- func NewBuilderModifier(builder Builder) func(op *core.Operation, next func(*core.Operation))
- func PrefixModifier(prefixes []string) func(o *core.Operation, next func(*core.Operation))
- func TestBuilder(builder Builder, op *core.Operation, handler func(core.Context)) func(core.Context)
- func TestChain(middlewares core.Middlewares, handler func(core.Context)) func(core.Context)
- func TestMiddleware(mw core.MiddlewareFunc, handler func(core.Context)) func(core.Context)
- type Builder
- type BuilderFunc
- type Group
- func (g *Group) Adapter() core.Adapter
- func (g *Group) Config() core.Config
- func (g *Group) DocumentOperation(op *core.Operation)
- func (g *Group) Group(prefix string) *Group
- func (g *Group) Marshal(w io.Writer, contentType string, v any) error
- func (g *Group) Middlewares() core.Middlewares
- func (g *Group) Negotiate(accept string) (string, error)
- func (g *Group) Transform(ctx core.Context, status string, v any) (any, error)
- func (g *Group) Unmarshal(contentType string, data []byte, v any) error
- func (g *Group) UseDefaultSecurity(scheme string)
- func (g *Group) UseDefaultTag(tag string)
- func (g *Group) UseMiddleware(middlewares ...core.MiddlewareFunc)
- func (g *Group) UseModifier(modifier func(o *core.Operation, next func(*core.Operation)))
- func (g *Group) UseSimpleModifier(modifier func(o *core.Operation))
- func (g *Group) UseTransformer(transformers ...core.Transformer)
- func (g *Group) WithSecurity(name string, scheme *core.SecurityScheme, fn core.MiddlewareFunc)
- type OperationDocumenter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Build ¶
func Build(builder Builder, op *core.Operation) core.MiddlewareFunc
Build is a convenience function that calls builder.Build for the given operation.
func NewBuilderModifier ¶
NewBuilderModifier returns an operation modifier that prepends middleware produced by the given Builder to each operation's middleware chain.
func PrefixModifier ¶
PrefixModifier returns an operation modifier that prepends each of the given path prefixes to the operation, duplicating the operation when multiple prefixes are provided.
func TestBuilder ¶
func TestBuilder(builder Builder, op *core.Operation, handler func(core.Context)) func(core.Context)
TestBuilder builds middleware from a Builder for the given operation and composes it with a handler into a callable function for use in tests.
func TestChain ¶
TestChain composes a middleware chain with a handler into a single callable function for use in tests.
func TestMiddleware ¶
TestMiddleware wraps a single middleware and handler into a callable function for use in tests.
Types ¶
type Builder ¶
type Builder interface {
Build(op *core.Operation) core.MiddlewareFunc
}
Builder creates operation-specific middleware by inspecting the operation definition at registration time.
type BuilderFunc ¶
type BuilderFunc func(op *core.Operation) core.MiddlewareFunc
BuilderFunc is an adapter that allows ordinary functions to be used as a Builder.
func (BuilderFunc) Build ¶
func (f BuilderFunc) Build(op *core.Operation) core.MiddlewareFunc
Build calls the wrapped function to produce a middleware for the given operation.
type Group ¶
Group wraps a core.API to provide shared path prefixes, middleware, transformers, and operation modifiers for a set of routes.
func NewGroup ¶
NewGroup creates a new route group from the given API with optional path prefixes applied to all registered operations.
func (*Group) Adapter ¶
Adapter returns the group's adapter, which wraps the underlying API adapter to apply the group's modifiers during operation handling.
func (*Group) DocumentOperation ¶
DocumentOperation applies the group's modifiers to the operation and adds it to the OpenAPI documentation.
func (*Group) Middlewares ¶
func (g *Group) Middlewares() core.Middlewares
Middlewares returns the combined middleware chain of the parent API followed by this group's own middleware.
func (*Group) Transform ¶
Transform runs the parent API's transformers followed by the group's own transformers on the response value.
func (*Group) UseDefaultSecurity ¶ added in v1.2.0
UseDefaultSecurity sets a default security requirement for operations in this group. If an operation already specifies security, it is left unchanged.
func (*Group) UseDefaultTag ¶ added in v1.2.0
UseDefaultTag sets a default tag for operations in this group. If an operation already specifies tags, they are left unchanged.
func (*Group) UseMiddleware ¶
func (g *Group) UseMiddleware(middlewares ...core.MiddlewareFunc)
UseMiddleware appends middleware functions to the group's middleware chain.
func (*Group) UseModifier ¶
UseModifier adds an operation modifier that can inspect and transform operations as they are registered, calling next to continue the chain.
func (*Group) UseSimpleModifier ¶
UseSimpleModifier adds an operation modifier that transforms the operation without needing to call a next function.
func (*Group) UseTransformer ¶
func (g *Group) UseTransformer(transformers ...core.Transformer)
UseTransformer appends response transformers to the group's transformer chain.
func (*Group) WithSecurity ¶ added in v1.2.0
func (g *Group) WithSecurity(name string, scheme *core.SecurityScheme, fn core.MiddlewareFunc)
WithSecurity registers a security scheme in the OpenAPI spec, applies the security requirement to all operations in this group, and adds the middleware to the group's chain. This is a one-call replacement for manually registering the scheme, calling UseDefaultSecurity, and UseMiddleware separately.
type OperationDocumenter ¶
OperationDocumenter is implemented by types that can register an operation into the OpenAPI documentation.