middleware

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2023 License: MIT Imports: 15 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 ContentTypeToLogBody = []string{
	"application/json",
	"application/xml",
	"text/json",
	"text/xml",
	"text/plain",
}

ContentTypeToLogBody is a list of content-type that the body will be logged.

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

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

Functions

func GetCustomerID added in v1.3.0

func GetCustomerID(ctx context.Context) int

GetCustomerID retrieve id from ctx. Return -1 of type assertion fail.

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.

func SetCustomerID added in v1.3.0

func SetCustomerID(ctx context.Context, id int) context.Context

SetCustomerID returns a new context using ctx as parent and inserting id.

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))

type JWTConfig added in v1.3.0

type JWTConfig struct {
	Secret string `env:"JWT_SECRET,required"`
	Issuer string `env:"JWT_ISSUER,default=https://faci.ly"`
}

JWTConfig contains the requirements to validate a jwt token.

func (JWTConfig) JWTMW added in v1.3.0

func (j JWTConfig) JWTMW(next http.Handler) http.Handler

JWTMW middleware checks for jwt token and if present validate and populate with custom claim ID. ID can be retrieved using GetCustomerID.

Jump to

Keyboard shortcuts

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