middleware

package
v0.0.0-...-b203f02 Latest Latest
Warning

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

Go to latest
Published: May 28, 2024 License: Apache-2.0 Imports: 19 Imported by: 1

Documentation

Index

Constants

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

Variables

This section is empty.

Functions

func Auth

func Auth(token auth.Token) func(http.Handler) http.Handler

func AuthOptional

func AuthOptional(token auth.Token) func(http.Handler) http.Handler

Attempts to get the auth token from the HTTP Authorization header, decrypt it, and place it on the context, but allows requests through even if they don't have this header field

func GetClaimsFromContext

func GetClaimsFromContext(ctx context.Context) auth.Claim

func GetDBConnFromContext

func GetDBConnFromContext(ctx context.Context) *sql.DB

func GetDBFromContext

func GetDBFromContext[T any](ctx context.Context, f func(*sql.DB) T) T

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 GetStack

func GetStack(skip int) []byte

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