Documentation
¶
Index ¶
- Variables
- func DetectClient(req *http.Request) models.ClientType
- func Etag(next http.Handler) http.Handler
- func ExtractUserFromSession(next http.Handler) http.Handler
- func Logger(next http.Handler) http.Handler
- func Otel(next http.Handler) http.Handler
- func PushCriticalAssets(next http.Handler) http.Handler
- func RateLimit(next http.Handler) http.Handler
- func Recoverer(next http.Handler) http.Handler
- func RequireHTMX(next http.Handler) http.Handler
- func RequireValidUser(next http.Handler) http.Handler
- func SetClient(next http.Handler) http.Handler
- func SetupHTMX(next http.Handler) http.Handler
- type RateLimiter
Constants ¶
This section is empty.
Variables ¶
var NewRateLimiter = sync.OnceValue(func() RateLimiter { strategy, err := realclientip.NewRightmostNonPrivateStrategy(clientIPHeader) if err != nil { panic("realclientip.NewRightmostNonPrivateStrategy returned error (bad input)") } lmt := tollbooth.NewLimiter(maxRequestsPerSecond, &limiter.ExpirableOptions{DefaultExpirationTTL: time.Hour}). SetIPLookup(limiter.IPLookup{ Name: clientIPHeader, IndexFromRight: 0, }). SetBurst(3) rateLimiter = RateLimiter{ strategy: strategy, limiter: lmt, } return rateLimiter })
NewRateLimiter initialises data for a rate limiter middleware.
Functions ¶
func DetectClient ¶ added in v0.154.0
func DetectClient(req *http.Request) models.ClientType
DetectClient detects the type of client accessing the app.
func Etag ¶
Etag calculates and adds an appropriate e-tag header to the response.
https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/ETag
func ExtractUserFromSession ¶ added in v0.143.0
ExtractUserFromSession will extract the user data from the session, retrieve the user details from the backend and then store the user object in the context for use by later handlers.
func PushCriticalAssets ¶ added in v0.39.0
PushCriticalAssets will optimistically send our custom script/css bundles to a client before it asks for them, which hopefully will speed up first page load.
func RateLimit ¶
RateLimit middleware will try to rate limit incoming requests with a pre-defined strategy.
func Recoverer ¶ added in v0.134.0
Recoverer is a modified version of the standard chi Recoverer middleware that additional logs to the GCP error console.
func RequireHTMX ¶
RequireHTMX middleware will only pass control to the next handler if the request is htmx powered. If not, it will return 403: Forbidden response.
func RequireValidUser ¶ added in v0.143.0
RequireValidUser will ensure that protected routes have a valid user status before continuing.
Types ¶
type RateLimiter ¶
type RateLimiter struct {
// contains filtered or unexported fields
}
RateLimiter holds options for controlling a rate limiter middleware.