Documentation
¶
Index ¶
- Constants
- func APIKeyAuth() gin.HandlerFunc
- func AuditManagementWrite() gin.HandlerFunc
- func Auth() gin.HandlerFunc
- func ClearLoginFailures(key string)
- func Cors() gin.HandlerFunc
- func DevMockPublicSuccess() gin.HandlerFunc
- func EmailCodeRateLimit() gin.HandlerFunc
- func JWTExpiryToSeconds(expiry string) int
- func Logger() gin.HandlerFunc
- func LoginRateLimit() gin.HandlerFunc
- func MaintenanceGuard() gin.HandlerFunc
- func RecordLoginFailure(key string, now time.Time)
- func RequireJSON() gin.HandlerFunc
- func RequirePermission(perm auth.Permission) gin.HandlerFunc
- func SecurityHeaders() gin.HandlerFunc
- func SetJWTCookie(c *gin.Context, token string, maxAge int)
- func ShouldAuditManagementWrite(method, fullPath string) bool
- func StaticEmbed(urlPrefix string, embedFS fs.FS) gin.HandlerFunc
- func StaticLocal(urlPrefix string, localPath string) gin.HandlerFunc
- func VerifyTurnstile() gin.HandlerFunc
Constants ¶
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 ¶
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 ¶
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 ¶
SetJWTCookie writes (or clears) the JWT HttpOnly cookie on the response. Pass maxAge <= 0 to delete the cookie.
func ShouldAuditManagementWrite ¶
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.