middleware

package
v0.59.0 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2023 License: Apache-2.0 Imports: 3 Imported by: 145

Documentation

Overview

Package middleware provides a middleware interface for ogen.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HookMiddleware

func HookMiddleware[RequestType, ParamsType, ResponseType any](
	m Middleware,
	req Request,
	unpack func(Parameters) ParamsType,
	cb func(context.Context, RequestType, ParamsType) (ResponseType, error),
) (r ResponseType, err error)

HookMiddleware is a helper that does ogen request type -> Request type conversion.

NB: this is an internal func, not intended for public use.

Types

type Middleware

type Middleware func(req Request, next Next) (Response, error)

Middleware is middleware type.

func ChainMiddlewares

func ChainMiddlewares(m ...Middleware) Middleware

ChainMiddlewares chains middlewares into a single middleware, which will be executed in the order they are passed.

type Next

type Next = func(req Request) (Response, error)

Next is the next middleware/handler in the chain.

type ParameterKey added in v0.55.0

type ParameterKey struct {
	// Name is the name of the parameter.
	Name string
	// In is the location of the parameter.
	In openapi.ParameterLocation
}

ParameterKey is a map key for parameters.

type Parameters added in v0.55.0

type Parameters map[ParameterKey]any

Parameters is a map of parameters.

func (Parameters) Cookie added in v0.55.0

func (p Parameters) Cookie(name string) (any, bool)

Cookie returns a parameter from the cookie.

func (Parameters) Header added in v0.55.0

func (p Parameters) Header(name string) (any, bool)

Header returns a parameter from the header.

func (Parameters) Path added in v0.55.0

func (p Parameters) Path(name string) (any, bool)

Path returns a parameter from the path.

func (Parameters) Query added in v0.55.0

func (p Parameters) Query(name string) (any, bool)

Query returns a parameter from the query.

type Request

type Request struct {
	// Context is request context.
	Context context.Context
	// OperationName is the ogen operation name. It is guaranteed to be unique and not empty.
	OperationName string
	// OperationID is the spec operation ID, if any.
	OperationID string
	// Body is the operation request body. May be nil, if the operation has not body.
	Body any
	// Params is the operation parameters.
	Params Parameters
	// Raw is the raw http request.
	Raw *http.Request
}

Request is request context type for middleware.

type Response

type Response struct {
	// Type is the operation response type.
	Type any
}

Response is response type for middleware.

Jump to

Keyboard shortcuts

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