middleware

package
v0.53.0 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2022 License: Apache-2.0 Imports: 2 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(map[string]any) 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 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 map[string]any
	// 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