middleware

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package middleware is about middlewares that must be added to chi handler. ex: r.Use(coreMiddleware.logger(dep.Components.Logger))

Index

Constants

This section is empty.

Variables

View Source
var DontLogBodyOnSuccess = []string{
	"/swagger",
	"/metrics",
	"/health",
}

DontLogBodyOnSuccess default prefix to not log response in case of success.

Functions

func Logger

func Logger(logger log.Logger) func(next http.Handler) http.Handler

Logger middleware is a middleware to log everything request that was receved by API.

func Recoverer

func Recoverer(logger log.Logger) func(next http.Handler) http.Handler

Recoverer middleware recover panic if it hapens into a request avoiding the application stop due uncacthed panic.

Types

type Info added in v1.2.0

type Info struct {
	// Host need to be ingress value without schema. Eg.: example.com:8080.
	Host string `env:"SWAGGER_HOST,required"`
}

Info is used to load environment variable with the value we want to modify at run time.

func (Info) Handler added in v1.2.0

func (s Info) Handler(refToSwaggerHost *string) http.Handler

Handler refToSwaggerHost point to SwaggerInfo.Host generated value and return an http.Handler to be mounted.

First generate swagger files:

make swagger

Mount desired route invoking this method with SwaggerInfo from generated files:

r.Mount("/swagger", dep.Components.Swagger.Handler(&docs.SwaggerInfo.Host))

Jump to

Keyboard shortcuts

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