Documentation ¶
Index ¶
- Variables
- func CORSMiddleware(opts CORSOptions) func(http.HandlerFunc) http.HandlerFunc
- func CSRFMiddleware(next http.HandlerFunc, isValidToken func(string) bool) http.HandlerFunc
- func DefaultErrorHandler(w http.ResponseWriter, message string, code int)
- func DefaultTokenExtractor(r *http.Request) (string, error)
- func GenerateCSRFToken() string
- func LoggingMiddleware(next http.HandlerFunc) http.HandlerFunc
- func NewAuthMiddleware(config JWTConfig) func(http.HandlerFunc) http.HandlerFunc
- func TimeoutMiddleware(timeout time.Duration) router.Middleware
- type CORSOptions
- type JWTConfig
Constants ¶
This section is empty.
Variables ¶
View Source
var DefaultCORSOptions = CORSOptions{ AllowOrigin: "*", AllowHeaders: []string{"Content-Type", "Authorization"}, ExposeHeaders: []string{}, AllowMethods: []string{http.MethodGet, http.MethodHead, http.MethodDelete, http.MethodOptions, http.MethodPatch, http.MethodPost}, AllowCredentials: false, MaxAge: 600, }
Functions ¶
func CORSMiddleware ¶
func CORSMiddleware(opts CORSOptions) func(http.HandlerFunc) http.HandlerFunc
CORSMiddleware creates a middleware function that applies the given CORS options.
func CSRFMiddleware ¶
func CSRFMiddleware(next http.HandlerFunc, isValidToken func(string) bool) http.HandlerFunc
func DefaultErrorHandler ¶
func DefaultErrorHandler(w http.ResponseWriter, message string, code int)
func GenerateCSRFToken ¶
func GenerateCSRFToken() string
func LoggingMiddleware ¶
func LoggingMiddleware(next http.HandlerFunc) http.HandlerFunc
func NewAuthMiddleware ¶
func NewAuthMiddleware(config JWTConfig) func(http.HandlerFunc) http.HandlerFunc
func TimeoutMiddleware ¶
func TimeoutMiddleware(timeout time.Duration) router.Middleware
Types ¶
type CORSOptions ¶
type CORSOptions struct { // AllowOrigin specifies the allowed origin for cross-origin requests. // Use "*" to allow any origin or specify a specific origin like "http://example.com". AllowOrigin string // AllowMethods lists the HTTP methods that are allowed for cross-origin requests. // Common methods include "GET", "POST", "PUT", etc. AllowMethods []string // AllowHeaders lists the headers that can be used during a request. // This includes headers such as "Content-Type", "Authorization", etc. AllowHeaders []string // AllowCredentials indicates whether credentials (cookies, HTTP authentication, etc.) // are allowed in cross-origin requests. Set to true to allow credentials. AllowCredentials bool // ExposeHeaders specifies the headers that can be exposed to the browser. // This allows the client to read these headers from the response. ExposeHeaders []string // MaxAge defines how long (in seconds) the results of a preflight request can be cached. // A longer MaxAge reduces the number of preflight requests. Set to 0 to disable caching. MaxAge int }
Click to show internal directories.
Click to hide internal directories.