middleware

package module
v0.0.0-...-604cd33 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2023 License: MIT Imports: 13 Imported by: 0

README

Echo Middleware

Echo Middleware is a set of custom middleware and extensions for Echo I've written for my use cases. At present this module includes:

  • Request Logging using Zap
  • Request Logging using ZeroLog
  • Instrumenting Handlers using Prometheus

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Prometheus

func Prometheus() echo.MiddlewareFunc

func PrometheusWithConfig

func PrometheusWithConfig(conf PrometheusConfig) echo.MiddlewareFunc

func ZapLogger

func ZapLogger(logger *zap.Logger) echo.MiddlewareFunc

ZapLogger returns a middleware that logs HTTP requests using Uber Zap with a sane default configuration.

func ZapLoggerWithConfig

func ZapLoggerWithConfig(logger *zap.Logger, config LoggerConfig) echo.MiddlewareFunc

func ZeroLogger

func ZeroLogger(logger zerolog.Logger) echo.MiddlewareFunc

func ZeroLoggerWithConfig

func ZeroLoggerWithConfig(logger zerolog.Logger, config LoggerConfig) echo.MiddlewareFunc

Types

type LoggerConfig

type LoggerConfig struct {
	// Skipper defines a function to skip the middleware. The zero-value/default
	// is to always execute the middleware.
	Skipper middleware.Skipper
	// Configures/extracts the value used for the "correlation_id" value that is
	// logged. The zero-value/default behavior is to use X-Request-ID from the
	// request HTTP header.
	CorrelationIDExtractor func(c echo.Context) string
	// Controls if HTTP headers are logged for the request and response. The
	// zero-value/default behavior is to not log the HTTP headers.
	//
	// Notice: Logging HTTP headers can contain sensitive information and may
	// be a security/privacy risk.
	Headers bool
	// Controls if the HTTP request body is logged. The zero-value/default behavior
	// is to not log the HTTP request body.
	//
	// Notice: The HTTP request body can contain sensitive information and may
	// be a security/privacy risk to log.
	RequestBody bool
	// Controls if the HTTP response body is logged. The zero-value/default behavior
	// is to not log the HTTP response body.
	//
	// Notice: The HTTP response body can contain sensitive information and may
	// be a security/privacy risk to log.
	ResponseBody bool
}

LoggerConfig controls the behavior of the logging middlewares.

type PrometheusConfig

type PrometheusConfig struct {

	// Allows the middleware to inspect the request and decide to skip the
	// middleware.
	Skipper middleware.Skipper

	Namespace      string
	Subsystem      string
	LatencyBuckets []float64
	SizeBuckets    []float64
	ConstLabels    map[string]string
	Registerer     prometheus.Registerer
}

Jump to

Keyboard shortcuts

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