middleware

package
v0.0.0-...-6aee27a Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildContextForUser

func BuildContextForUser(ctx context.Context, db *database.Connection, userID int64, isSuperAdmin, isHeadless bool) context.Context

func InjectAdmin

func InjectAdmin(ctx context.Context, isAdmin bool) context.Context

InjectAdmin is a helper function to add a flag denoting if the current user is an Administrator

func InjectIntoContext

func InjectIntoContext(ctx context.Context, i InjectIntoContextInput) context.Context

InjectIntoContext adds a collection of data to the appropriate keys into the context.

func InjectPolicy

func InjectPolicy(ctx context.Context, p policy.Policy) context.Context

InjectPolicy is a helper function to add a policy to the context under the expected key

func InjectUser

func InjectUser(ctx context.Context, userID int64) context.Context

InjectUser is a helper function to add a user to the context under the expected key

func IsAdmin

func IsAdmin(ctx context.Context) bool

IsAdmin is used to check if the current user has been identified as an admin. Note that this value will only change when the session store is cleared for this user (i.e. they log out)

func Policy

func Policy(ctx context.Context) policy.Policy

Policy is used to retrieve policy from context

func UserID

func UserID(ctx context.Context) int64

UserID is used to retrieve the user id from context

Types

type InjectIntoContextInput

type InjectIntoContextInput struct {
	IsSuperAdmin bool
	UserID       int64
	UserPolicy   policy.Policy
}

InjectIntoContextInput is a small structure for defining what is placed into the context

type MiddlewareFunc

type MiddlewareFunc func(http.Handler) http.Handler

func AuthenticateAppAndInjectCtx

func AuthenticateAppAndInjectCtx(db *database.Connection) MiddlewareFunc

func AuthenticateUserAndInjectCtx

func AuthenticateUserAndInjectCtx(db *database.Connection, sessionStore *session.Store) MiddlewareFunc

func InjectCSRFTokenHeader

func InjectCSRFTokenHeader() MiddlewareFunc

func LogRequests

func LogRequests(baseLogger logging.Logger) MiddlewareFunc

type UserData

type UserData struct {
	ID       int64
	Headless bool
}

Jump to

Keyboard shortcuts

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