package
0.7.5
Repository: https://github.com/infiniteloopcloud/go.git
Documentation: pkg.go.dev

# README

Middlewares

Commonly used middlewares in microservices

Correlation

Try to access the Ctx_correlation_id in the header. If it's not exists it will create a new one and attach it to context.

package main

import (
	"github.com/go-chi/chi/v5"
	"github.com/infiniteloopcloud/middlewares"
)

func main() {
	r := chi.NewRouter()
	r.Use(middlewares.Correlation())
}

Context

Context middleware load the values sent in the header from the sender's context into the request's context.

package main

import (
	"github.com/go-chi/chi/v5"
	"github.com/infiniteloopcloud/middlewares"
)

func main() {
	r := chi.NewRouter()
	r.Use(middlewares.Context())
}

CORS

Setup CORS's server-side settings

package main

import (
	"github.com/go-chi/chi/v5"
    "github.com/go-chi/cors"
	"github.com/infiniteloopcloud/middlewares"
)

func main() {
	r := chi.NewRouter()
	r.Use(cors.Handler(middlewares.Cors()))
}

Log

Add custom request/response logging

package main

import (
	"github.com/go-chi/chi/v5"
	"github.com/infiniteloopcloud/log"
	"github.com/infiniteloopcloud/middlewares"
)

func main() {
	r := chi.NewRouter()
	r.Use(middlewares.CustomLog(middlewares.LogOpts{LogLevel: log.LevelToUint()}))
}

Prometheus

Collect metrics of request/responses

package main

import (
	"github.com/go-chi/chi/v5"
	"github.com/infiniteloopcloud/middlewares"
)

func main() {
	r := chi.NewRouter()
	r.Use(middlewares.Prometheus)
}

# Functions

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
CustomLog middleware is responsible for setting the logLevel.
CustomWriter wraps the http.ResponseWriter into a new hyper.Writer.
No description provided by the author
LogResponse middleware is responsible for log the response body.
No description provided by the author
No description provided by the author
No description provided by the author
Recoverer is a middleware that recovers from panics, logs the panic (and a backtrace), and returns a HTTP 500 (Internal Server Error) status if possible.
nolint:forbidigo.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Variables

No description provided by the author
No description provided by the author

# Structs

No description provided by the author
No description provided by the author
No description provided by the author

# Interfaces

No description provided by the author

# Type aliases

No description provided by the author