middlewares

package
v0.237.0 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2026 License: AGPL-3.0 Imports: 32 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 CanonicalizeListFilters added in v0.221.2

func CanonicalizeListFilters(session handlers.SessionManager) func(next http.Handler) http.Handler

CanonicalizeListFilters handles processing and storing the fully-specified, whitelisted list filters for the user.

func CanonicalizeSearchParams added in v0.221.2

func CanonicalizeSearchParams(session handlers.SessionManager) func(next http.Handler) http.Handler

CanonicalizeSearchParams processes and stores the search params requested by a user.

func DetectClient added in v0.154.0

func DetectClient(req *http.Request) models.ClientType

DetectClient detects the type of client accessing the app.

func ExtractUserFromSession added in v0.143.0

func ExtractUserFromSession(
	users UserService,
	auth *auth0.Authenticator,
	session handlers.SessionManager,
	httpClient *resty.Client,
) func(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 NoCache added in v0.212.0

func NoCache(next http.Handler) http.Handler

NoCache ensures no caching will be applied.

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 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 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.

Types

type AppConfig added in v0.235.0

type AppConfig interface {
	GetAppID() string
	GetAppVersion() string
	GetAppName() string
	GetAppEnvironment() config.Environment
	IsProduction() bool
	GetBaseURL() *url.URL
}

type RateLimiter

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

RateLimiter holds options for controlling a rate limiter middleware.

type UserService added in v0.235.0

type UserService interface {
	GetUserByExternalID(ctx context.Context, externalID string) (*models.User, error)
}

Jump to

Keyboard shortcuts

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