middleware

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2026 License: MPL-2.0 Imports: 4 Imported by: 0

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

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

func NewBuilderModifier(builder Builder) func(op *core.Operation, next func(*core.Operation))

NewBuilderModifier returns an operation modifier that prepends middleware produced by the given Builder to each operation's middleware chain.

func PrefixModifier

func PrefixModifier(prefixes []string) func(o *core.Operation, next func(*core.Operation))

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

func TestChain(middlewares core.Middlewares, handler func(core.Context)) func(core.Context)

TestChain composes a middleware chain with a handler into a single callable function for use in tests.

func TestMiddleware

func TestMiddleware(mw core.MiddlewareFunc, handler func(core.Context)) func(core.Context)

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

Build calls the wrapped function to produce a middleware for the given operation.

type Group

type Group struct {
	core.API
	// contains filtered or unexported fields
}

Group wraps a core.API to provide shared path prefixes, middleware, transformers, and operation modifiers for a set of routes.

func NewGroup

func NewGroup(api core.API, prefixes ...string) *Group

NewGroup creates a new route group from the given API with optional path prefixes applied to all registered operations.

func (*Group) Adapter

func (g *Group) Adapter() core.Adapter

Adapter returns the group's adapter, which wraps the underlying API adapter to apply the group's modifiers during operation handling.

func (*Group) Config

func (g *Group) Config() core.Config

Config returns the configuration from the underlying API, if available.

func (*Group) DocumentOperation

func (g *Group) DocumentOperation(op *core.Operation)

DocumentOperation applies the group's modifiers to the operation and adds it to the OpenAPI documentation.

func (*Group) Group

func (g *Group) Group(prefix string) *Group

Group creates a sub-group with the given path prefix.

func (*Group) Marshal

func (g *Group) Marshal(w io.Writer, contentType string, v any) error

Marshal delegates response marshalling to the underlying API.

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) Negotiate

func (g *Group) Negotiate(accept string) (string, error)

Negotiate delegates content negotiation to the underlying API.

func (*Group) Transform

func (g *Group) Transform(ctx core.Context, status string, v any) (any, error)

Transform runs the parent API's transformers followed by the group's own transformers on the response value.

func (*Group) Unmarshal

func (g *Group) Unmarshal(contentType string, data []byte, v any) error

Unmarshal delegates request unmarshalling to the underlying API.

func (*Group) UseDefaultSecurity added in v1.2.0

func (g *Group) UseDefaultSecurity(scheme string)

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

func (g *Group) UseDefaultTag(tag string)

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

func (g *Group) UseModifier(modifier func(o *core.Operation, next func(*core.Operation)))

UseModifier adds an operation modifier that can inspect and transform operations as they are registered, calling next to continue the chain.

func (*Group) UseSimpleModifier

func (g *Group) UseSimpleModifier(modifier func(o *core.Operation))

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

type OperationDocumenter interface {
	DocumentOperation(op *core.Operation)
}

OperationDocumenter is implemented by types that can register an operation into the OpenAPI documentation.

Jump to

Keyboard shortcuts

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