middleware

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2021 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// RequestIDLogKey represents a request ID key logger field.
	RequestIDLogKey = "request_id"

	// ChartIDLogKey represents a chart ID key logger field.
	ChartIDLogKey = "chart_id"
)

Variables

This section is empty.

Functions

func BackendCheck

func BackendCheck(log *zerolog.Logger, b backend.Backend) func(next http.Handler) http.Handler

BackendCheck checks if backend is healthy and returns http.StatusServiceUnavailable if it's not.

func GetChartID

func GetChartID(ctx context.Context) string

GetChartID retrieves chart_id value from context.

func GetCreateChartRequest

func GetCreateChartRequest(ctx context.Context) *render.CreateChartRequest

GetCreateChartRequest retrieves create chart request from context.

func GetRequestID

func GetRequestID(ctx context.Context) string

GetRequestID returns request ID or empty string if it's not set.

func MarshalJSON

func MarshalJSON(w http.ResponseWriter, statusCode int, v interface{})

MarshalJSON marshals 'v' to JSON, automatically escaping HTML, setting the Content-Type as application/json and writing headers with the provided status code. It calls http.Error in case of failures.

func Recover

func Recover(log *zerolog.Logger) func(next http.Handler) http.Handler

Recover catches panics and returns the Internal Server Error back to the caller.

func RequestObserver

func RequestObserver(log *zerolog.Logger, mrec metric.Recorder) func(next http.Handler) http.Handler

RequestObserver handles observability (metrics and logging) for every request.

func RequireChartID

func RequireChartID(log *zerolog.Logger) func(next http.Handler) http.Handler

RequireChartID checks that chart_id parameter can be used and stores it in the context.

func RequireCreateChartParams

func RequireCreateChartParams(log *zerolog.Logger) func(next http.Handler) http.Handler

RequireCreateChartParams checks if provided create chart parameters body can be used and stores it in the context.

func SetRequestID

func SetRequestID(log *zerolog.Logger) func(next http.Handler) http.Handler

SetRequestID request ID and saves it into the context.

Types

This section is empty.

Jump to

Keyboard shortcuts

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