middleware

package
v0.0.0-...-0a38112 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2024 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultNooperation = Nooperation()

DefaultNooperation is a default instance for Nooperation middleware

View Source
var DefaultRequestResponseValidatorConfig = RequestResponseValidatorConfig{
	Skipper:          echo_middleware.DefaultSkipper,
	ValidateRequest:  true,
	ValidateResponse: false,
}

DefaultRequestResponseValidatorConfig is the default RequestResponseValidator middleware config.

Functions

func CreateMetricsMiddleware

func CreateMetricsMiddleware(metrics *metrics.Metrics) echo.MiddlewareFunc

func InitOpenAPIFormats

func InitOpenAPIFormats()

InitOpenAPIFormats configure the admited formats in the openapi specification. This function must be called before receive any request. Suggested to call before instantiate the middleware.

func MatchedRoute

func MatchedRoute(ctx echo.Context) string

See: https://github.com/labstack/echo/pull/1502/files This method exist for v5 echo framework

func MetricsMiddlewareWithConfig

func MetricsMiddlewareWithConfig(config *MetricsConfig) echo.MiddlewareFunc

func NewAuthenticator

func NewAuthenticator() openapi3filter.AuthenticationFunc

NewAuthenticator create an authenticator for the public API

func Nooperation

func Nooperation() echo.MiddlewareFunc

Nooperation is a middleware that do nothing. This is useful to decouple middleware initialisation from middleware wiring, so if some middleware is option based on some configuration, we only have to assign this middleware instead of add middlewares in a conditional way.

func RequestResponseValidator

func RequestResponseValidator() echo.MiddlewareFunc

RequestResponseValidator returns a middleware which validates the HTTP response

func RequestResponseValidatorWithConfig

func RequestResponseValidatorWithConfig(config *RequestResponseValidatorConfig) echo.MiddlewareFunc

func SLogMiddlewareWithConfig

func SLogMiddlewareWithConfig(cfg *SLogMiddlewareConfig) echo.MiddlewareFunc

SLogMiddlewareWithConfig create a middleware for logging config provides

func SLogRequest

func SLogRequest(ctx context.Context, err error, method, path string, status int)

SLogRequest write a log entry with the request information

Types

type MetricsConfig

type MetricsConfig struct {
	Skipper echo_middleware.Skipper
	Metrics *metrics.Metrics
}

type RequestResponseValidatorConfig

type RequestResponseValidatorConfig struct {
	// Skipper defines a function to skip middleware.
	Skipper          echo_middleware.Skipper
	ValidateRequest  bool
	ValidateResponse bool
}

RequestResponseValidatorConfig defines the config for RequestResponseValidator middleware.

type ResponseRecorder

type ResponseRecorder struct {
	// contains filtered or unexported fields
}

In order to validate a response, we need to have access to the bytes of the response. The following code allows us to get access to it.

func (*ResponseRecorder) Header

func (r *ResponseRecorder) Header() http.Header

Implements Header of http.ResponseWriter

func (*ResponseRecorder) Write

func (r *ResponseRecorder) Write(p []byte) (n int, err error)

Implements Write of http.ResponseWriter

func (*ResponseRecorder) WriteHeader

func (r *ResponseRecorder) WriteHeader(statusCode int)

Implements WriteHeader of http.ResponseWriter

type SLogMiddlewareConfig

type SLogMiddlewareConfig struct {
	Skipper middleware.Skipper
	Log     *slog.Logger
}

SLogMiddlewareConfig hold the configuration for the echo slog middleware

Jump to

Keyboard shortcuts

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