Documentation
¶
Index ¶
- Constants
- func Auth(db *sql.DB, next http.Handler) http.Handler
- func CSRF(next http.Handler) http.Handler
- func GetClientIP(r *http.Request) string
- func GetRequestID(r *http.Request) string
- func GetUserID(r *http.Request) int
- func GetUserRole(r *http.Request) string
- func LocalhostOnly(next http.Handler) http.Handler
- func Logger(next http.Handler) http.Handler
- func LoginRateLimitMiddleware(next http.Handler) http.Handler
- func RateLimit(next http.HandlerFunc) http.HandlerFunc
- func RateLimitMiddleware(next http.Handler) http.Handler
- func RequestID(next http.Handler) http.Handler
- func RequireAdmin(next http.Handler) http.Handler
- func SecurityHeaders(next http.Handler) http.Handler
- func StopGlobalLimiter()
- type BoundedRateLimiter
Constants ¶
const ( UserIDKey contextKey = "user_id" UserRoleKey contextKey = "user_role" RequestIDKey contextKey = "request_id" )
Variables ¶
This section is empty.
Functions ¶
func GetClientIP ¶
GetClientIP extracts real client IP, only trusting X-Forwarded-For from known proxies Exported for use by handlers and other packages
func GetRequestID ¶
GetRequestID retrieves request ID from context
func GetUserRole ¶
GetUserRole retrieves user role from request context
func LocalhostOnly ¶
LocalhostOnly middleware restricts access to localhost (127.0.0.1) only This is used for the internal CLI API that bypasses authentication. It strictly checks RemoteAddr to prevent X-Forwarded-For spoofing.
func LoginRateLimitMiddleware ¶
LoginRateLimitMiddleware applies tighter rate limiting to login attempts
func RateLimit ¶
func RateLimit(next http.HandlerFunc) http.HandlerFunc
RateLimit middleware for http.HandlerFunc (backwards compat)
func RateLimitMiddleware ¶
RateLimitMiddleware applies rate limiting to http.Handler
func RequireAdmin ¶
RequireAdmin middleware ensures user has admin role
func SecurityHeaders ¶
SecurityHeaders adds security headers to all responses
func StopGlobalLimiter ¶
func StopGlobalLimiter()
StopGlobalLimiter stops the global rate limiter cleanup goroutine
Types ¶
type BoundedRateLimiter ¶
type BoundedRateLimiter struct {
// contains filtered or unexported fields
}
func NewBoundedRateLimiter ¶
func NewBoundedRateLimiter(maxSize, limit int, window time.Duration) *BoundedRateLimiter
func (*BoundedRateLimiter) Stop ¶
func (rl *BoundedRateLimiter) Stop()
Stop gracefully stops the rate limiter cleanup goroutine