middleware

package
v0.0.0-...-b0afd99 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2021 License: CC0-1.0 Imports: 10 Imported by: 0

Documentation

Overview

Package middleware implements middleware functions. It contains both app-specific middleware functions, as well as more generic ones.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AttachUserAndLogger

func AttachUserAndLogger[Ctx context.Context, In, Out any](h th.Handler[MyAppContext, In, Out]) th.Handler[Ctx, In, Out]

AttachUserAndLogger fetches and attaches the user ID and attaches a request-specific logger.

func SetHandlerTimeout

func SetHandlerTimeout[Ctx tc.TypedContext[Ctx], In, Out any](timeout time.Duration, h th.Handler[Ctx, In, Out]) th.Handler[Ctx, In, Out]

SetHandlerTimeout returns a new handler with its timeout set to timeout.

Types

type MyAppContext

type MyAppContext struct {
	context.Context
	UserID UserID
	Logger logrus.FieldLogger
}

MyAppContext contains the UserID and a request-specific logger.

func (MyAppContext) InnerContext

func (mac MyAppContext) InnerContext() context.Context

InnerContext implements the typedcontext.TypedContext interface.

func (MyAppContext) WithInnerContext

func (mac MyAppContext) WithInnerContext(ctx context.Context) MyAppContext

WithInnerContext implements the typedcontext.TypedContext interface.

type UserID

type UserID int64

UserID represents the ID of the user. You'd probably have UserID somewhere else than in the middleware package though.

func UserIDFromString

func UserIDFromString(s string) (UserID, error)

UserIDFromString translates s into an UserID if it is valid.

Jump to

Keyboard shortcuts

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