middleware

package
v0.0.0-...-7b0100a Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2021 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// UserContextKey is used to fetch and store the user struct from context
	UserContextKey key = "user"
	// SiteContextKey is used to fetch and store the site struct from context
	SiteContextKey key = "site"
)

Variables

This section is empty.

Functions

func CanAccess

func CanAccess(db *gorm.DB, FeatureKey string, r *http.Request) bool

CanAccess checks if a user is allowed to access a specified feature

Types

type BeuboMiddleware

type BeuboMiddleware struct {
	DB            *gorm.DB
	PluginHandler *plugin.Handler
}

BeuboMiddleware holds parameters relevant to Beubo middlewares

func (*BeuboMiddleware) Auth

Auth checks if a user is authenticated and performs redirects if needed. The user struct is set to the request context if authenticated.

func (*BeuboMiddleware) Plugin

func (bmw *BeuboMiddleware) Plugin(w http.ResponseWriter, r *http.Request, next http.HandlerFunc)

Plugin allows plugins to perform actions as a middleware

func (*BeuboMiddleware) Site

Site determines if the domain is an existing site and performs relevant actions based on this

func (*BeuboMiddleware) Whitelist

func (bmw *BeuboMiddleware) Whitelist(rw http.ResponseWriter, r *http.Request, next http.HandlerFunc)

Whitelist checks the ip whitelist configuration. If ip whitelisting is enabled, it ensures the ip is whitelisted when accessing administrator pages

type Throttle

type Throttle struct {
	IPs     map[string]ThrottleClient
	Mu      *sync.RWMutex
	Rate    rate.Limit
	Burst   int
	Cleanup time.Duration
}

Throttle holds relevant parameters for configuring how the throttle middleware behaves

func (Throttle) Throttle

func (t Throttle) Throttle(w http.ResponseWriter, r *http.Request, next http.HandlerFunc)

Throttle prevents multiple repeated requests in a certain time period

type ThrottleClient

type ThrottleClient struct {
	Limiter *rate.Limiter
	// contains filtered or unexported fields
}

ThrottleClient holds info about an ip such as it's rate limiter and the last time a request was made

Jump to

Keyboard shortcuts

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