Documentation
¶
Index ¶
- Constants
- Variables
- func Authentication() router.MiddlewareFunc
- func Authorization(requiredPermission string) router.MiddlewareFunc
- func CORS(config CORSConfig) router.MiddlewareFunc
- func CacheControl(maxAge time.Duration, directives ...string) router.MiddlewareFunc
- func Compression() router.MiddlewareFunc
- func ContentTypeChecking(expectedContentType string) router.MiddlewareFunc
- func GetRequestID(ctx context.Context) string
- func Logging() router.MiddlewareFunc
- func RateLimiter(store Store) router.MiddlewareFunc
- func Recovery() router.MiddlewareFunc
- func RequestID() router.MiddlewareFunc
- func SessionManagement(store SessionStore) router.MiddlewareFunc
- type CORSConfig
- type Session
- type SessionStore
- type Store
Constants ¶
const ( // MaxRequests is the number of allowed requests in the defined time window. MaxRequests = 100 // TimeWindow is the duration in which the requests are counted. TimeWindow = time.Hour )
const (
// SecretKey used to sign JWTs. This should be kept private and secure.
SecretKey = "your_secret_key_here"
)
Variables ¶
var DefaultCORSConfig = CORSConfig{ AllowOrigins: []string{"*"}, AllowMethods: []string{"GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS"}, AllowHeaders: []string{"Origin", "Content-Type", "Accept", "Authorization"}, }
DefaultCORSConfig is a basic default configuration for CORS.
Functions ¶
func Authentication ¶
func Authentication() router.MiddlewareFunc
Authentication middleware using JWT
func Authorization ¶
func Authorization(requiredPermission string) router.MiddlewareFunc
Authorization middleware
func CacheControl ¶
func CacheControl(maxAge time.Duration, directives ...string) router.MiddlewareFunc
CacheControl sets the Cache-Control header for the response.
func Compression ¶
func Compression() router.MiddlewareFunc
Compression checks the request's Accept-Encoding header and, if appropriate, wraps the response writer in a gzip writer.
func ContentTypeChecking ¶
func ContentTypeChecking(expectedContentType string) router.MiddlewareFunc
ContentTypeChecking ensures that the client sends requests with the expected content type.
func GetRequestID ¶
GetRequestID retrieves the Request ID from the context.
func Logging ¶
func Logging() router.MiddlewareFunc
Logging logs the method, path, request ID, IP, user agent, and time for each request.
func RateLimiter ¶
func RateLimiter(store Store) router.MiddlewareFunc
RateLimiter is a middleware for rate limiting requests.
func Recovery ¶
func Recovery() router.MiddlewareFunc
Recovery recovers from panics and logs a stack trace.
func RequestID ¶
func RequestID() router.MiddlewareFunc
RequestID is a middleware that assigns a unique ID to each incoming request.
func SessionManagement ¶
func SessionManagement(store SessionStore) router.MiddlewareFunc
SessionManagement manages user sessions.
Types ¶
type CORSConfig ¶
CORSConfig defines the config for CORS middleware.