middleware

package
v0.0.0-...-bf09d72 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2020 License: Apache-2.0 Imports: 15 Imported by: 3

Documentation

Index

Constants

View Source
const (
	HeaderRequestID = "x-request-id"
)

Variables

This section is empty.

Functions

func GetDefaultLogger

func GetDefaultLogger(serviceName, environment string, level int) *logrus.Entry

GetDefaultLogger gets a default logger to use. level is a number from 0-7, 0 being the most strict and 7 the most verbose

func GetInsecureUserIDFromContext

func GetInsecureUserIDFromContext(ctx context.Context) string

getInsecureUserIDFromContext returns the user id or empty string if missing

func GetLoggerFromContext

func GetLoggerFromContext(ctx context.Context) *logrus.Entry

GetLoggerFromContext returns a logrus entry from the context, defaulting to a standard one if its not found

func GetRequestIDFromContext

func GetRequestIDFromContext(ctx context.Context) string

GetRequestIDFromContext returns the requestID or empty string if missing

func HandlerFunc

func HandlerFunc(h func(w http.ResponseWriter, r *http.Request) error) http.Handler

HandlerFunc converts a handler with an error to a standard handler

func NoCache

func NoCache(h http.Handler) http.Handler

NoCache will add the following headers to the response:

Cache-Control: no-cache, no-store, must-revalidate
Pragma: no-cache
Expires: 0

func Recovery

func Recovery(h http.Handler) http.Handler

Recovery handles panics

func RequestID

func RequestID(h http.Handler) http.Handler

RequestID adds a request id to the context, if available it will use the one in the x-request-id header

Types

type JWTDecoder

type JWTDecoder interface {
	DecodeSegment(seg string) ([]byte, error)
}

type Logger

type Logger interface {
	Log(h http.Handler) http.Handler
}

Logger injects a logger into the context

func NewLogrusLogger

func NewLogrusLogger(baseEntry *logrus.Entry, logRequests bool) Logger

NewLogrusLogger allows you to setup a base entry to use for logging

type Timer

type Timer interface {
	Time(name string) alice.Constructor
}

Timer can time a handler and log it

func NewNullTimer

func NewNullTimer() Timer

type UserIDIngector

type UserIDIngector interface {
	Inject(h http.Handler) http.Handler
}

UserIDIngector injects a UserID from a JWT into the context

func NewUserIDInjector

func NewUserIDInjector(jwt JWTDecoder) UserIDIngector

NewLogrusLogger allows you to setup a base entry to use for logging

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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