middleware

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2026 License: AGPL-3.0 Imports: 30 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	// JWTCookieName is the name of the HttpOnly cookie that stores the JWT token.
	JWTCookieName = "token"
)

Variables

This section is empty.

Functions

func APIKeyAuth

func APIKeyAuth() gin.HandlerFunc

func AuditManagementWrite

func AuditManagementWrite() gin.HandlerFunc

func Auth

func Auth() gin.HandlerFunc

func ClearLoginFailures

func ClearLoginFailures(key string)

ClearLoginFailures removes all recorded failures for the given key.

func Cors

func Cors() gin.HandlerFunc

func DevMockPublicSuccess

func DevMockPublicSuccess() gin.HandlerFunc

func EmailCodeRateLimit

func EmailCodeRateLimit() gin.HandlerFunc

EmailCodeRateLimit returns a gin middleware that enforces per-email and per-IP send limits for the /send-email-code endpoint.

func JWTExpiryToSeconds

func JWTExpiryToSeconds(expiry string) int

JWTExpiryToSeconds converts an expiry string (RFC3339 or "30m" style) to seconds for use as the cookie maxAge. Returns a default of 15 minutes on parse failure.

func Logger

func Logger() gin.HandlerFunc

func LoginRateLimit

func LoginRateLimit() gin.HandlerFunc

LoginRateLimit returns a gin middleware that enforces per-IP login attempt limits.

func MaintenanceGuard

func MaintenanceGuard() gin.HandlerFunc

MaintenanceGuard blocks non-staff management-plane writes while maintenance_mode is on. Staff (admin/editor) requests pass through so an admin can perform the maintenance and turn it off. The guard parses the JWT itself (it runs as a global middleware, before per-route Auth()), but only when a request actually needs gating — no token parse for reads, relay, or exempt paths.

func RecordLoginFailure

func RecordLoginFailure(key string, now time.Time)

RecordLoginFailure increments the failed-login counter for the given key.

func RequireJSON

func RequireJSON() gin.HandlerFunc

func RequirePermission

func RequirePermission(perm auth.Permission) gin.HandlerFunc

RequirePermission returns a middleware that checks if the authenticated user has the required permission.

func SecurityHeaders

func SecurityHeaders() gin.HandlerFunc

SecurityHeaders adds common security-related HTTP response headers.

func SetJWTCookie

func SetJWTCookie(c *gin.Context, token string, maxAge int)

SetJWTCookie writes (or clears) the JWT HttpOnly cookie on the response. Pass maxAge <= 0 to delete the cookie.

func ShouldAuditManagementWrite

func ShouldAuditManagementWrite(method, fullPath string) bool

ShouldAuditManagementWrite is the exported variant of shouldAuditManagementWrite, used by tests to verify route audit coverage.

func StaticEmbed

func StaticEmbed(urlPrefix string, embedFS fs.FS) gin.HandlerFunc

func StaticLocal

func StaticLocal(urlPrefix string, localPath string) gin.HandlerFunc

func VerifyTurnstile

func VerifyTurnstile() gin.HandlerFunc

VerifyTurnstile returns a gin.HandlerFunc that verifies the Cloudflare Turnstile token present in the request body field "cf_turnstile_response" or the HTTP header "cf-turnstile-response". If Turnstile is not enabled via settings, the middleware is a no-op and calls c.Next().

Types

This section is empty.

Jump to

Keyboard shortcuts

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