middlewares

package
v0.167.1 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2026 License: AGPL-3.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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

func Etag(next http.Handler) http.Handler

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

func ExtractUserFromSession(next http.Handler) http.Handler

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 Logger

func Logger(next http.Handler) http.Handler

func Otel added in v0.61.0

func Otel(next http.Handler) http.Handler

Otel is a middleware to configure open telemetry for the server.

func PushCriticalAssets added in v0.39.0

func PushCriticalAssets(next http.Handler) http.Handler

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

func RateLimit(next http.Handler) http.Handler

RateLimit middleware will try to rate limit incoming requests with a pre-defined strategy.

func Recoverer added in v0.134.0

func Recoverer(next http.Handler) http.Handler

Recoverer is a modified version of the standard chi Recoverer middleware that additional logs to the GCP error console.

func RequireHTMX

func RequireHTMX(next http.Handler) http.Handler

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

func RequireValidUser(next http.Handler) http.Handler

RequireValidUser will ensure that protected routes have a valid user status before continuing.

func SetClient added in v0.154.0

func SetClient(next http.Handler) http.Handler

SetClient is a middleware that detects and sets a client variable in the context.

func SetupHTMX

func SetupHTMX(next http.Handler) http.Handler

SetupHTMX middleware performs general setup for serving htmx-powered content.

Types

type RateLimiter

type RateLimiter struct {
	// contains filtered or unexported fields
}

RateLimiter holds options for controlling a rate limiter middleware.

Directories

Path Synopsis
Package etag implements middleware for handling the ETag header in responses.
Package etag implements middleware for handling the ETag header in responses.

Jump to

Keyboard shortcuts

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