modulepackage
1.1.0
Repository: https://github.com/faabiosr/echo-middleware.git
Documentation: pkg.go.dev
# README
Echo Framework - Middlewares
:tada: Overview
echo-middleware is a Go package that provides multiple middlewares for Echo Framework.
:relaxed: Motivation
After writing these middlewares several times, it was decided to create a package with useful middlewares for echo.
:dart: Installation
Requirements
echo-middleware requires Go 1.21 or later and Echo Framework v4.
How to use
Use go get.
$ go get github.com/faabiosr/echo-middleware
Then import the package into your own code:
import "github.com/faabiosr/echo-middleware"
:toolbox: Development
Requirements
- Install Go
- Install GolangCI-Lint
Makefile
Please run make help
to see all the available targets.
:page_with_curl: License
This project is released under the MIT licence. See LICENSE for more details.
# Functions
CharmLog returns a middleware that logs HTTP requests.
CharmLogRecoverFn returns a CharmLog recover log function to print panic errors.
CharmLogWithConfig returns a CharmBracelet Log middleware with config.
Logrus returns a middleware that logs HTTP requests.
LogrusRecoverFn returns a Logrus recover log function to print panic errors.
LogrusWithConfig returns a Logrus middleware with config.
OpenCensus returns a middleware that collect HTTP requests and response metrics.
OpenCensusWithConfig returns a OpenCensus middleware with config.
RequestID returns a middleware that reads or generates a new request id and returns to response, also stores in context.
RequestIDValue returns the value stored in the context, otherwise returns an empty string.
RequestIDWithConfig uses the echo.RequestIDWithConfig under the hood with custom generator and sets the request id in context.
ZapLog returns a middleware that logs HTTP requests.
ZapLogRecoverFn returns a ZapLog recover log function to print panic errors.
ZapLogWithConfig returns a Uber ZapLog middleware with config.
ZeroLog returns a middleware that logs HTTP requests.
ZeroLogRecoverFn returns a ZeroLog recover log function to print panic errors.
ZeroLogWithConfig returns a ZeroLog middleware with config.
# Variables
DefaultCharmLogConfig is the default CharmBracelet Log middleware config.
DefaultLogrusConfig is the default Logrus middleware config.
DefaultOpenCensusConfig is the default OpenCensus middleware config.
DefaultRequestIDConfig is the default RequestID middleware config, based on the echo.RequestIDConfig but with uuid generator instead.
DefaultZapLogConfig is the default Uber ZapLog middleware config.
DefaultZeroLogConfig is the default ZeroLog middleware config.
OpenCensusRequestCount counts the HTTP requests started.
OpenCensusRequestCountByMethod counts the HTTP requests by method.
OpenCensusRequestCountByPath counts the HTTP requests by path.
OpenCensusResponseCountByStatusCode counts the HTTP requests by status code.
# Structs
CharmLogConfig defines the config for CharmBracelet Log middleware.
LogrusConfig defines the config for Logrus middleware.
OpenCensusConfig defines the config for OpenCensus middleware.
ZapLogConfig defines the config for Uber ZapLog middleware.
ZeroLogConfig defines the config for ZeroLog middleware.
# Type aliases
RequestIDConfig alias for emw.RequestIDConfig.