Documentation
¶
Overview ¶
Package middleware provides reusable middleware for Gorbit.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AllowAllCORS ¶
AllowAllCORS returns a middleware that allows requests from any origin.
This is primarily intended for development or trusted environments.
func CORS ¶
func CORS(options ...CORSOptions) gb.Handler
CORS creates a configurable Cross-Origin Resource Sharing (CORS) middleware.
When no options are provided, the default configuration from DefaultCORS is used.
Example:
app.Use(middleware.CORS())
app.Use(middleware.CORS(middleware.CORSOptions{
AllowOrigins: []string{"https://example.com"},
AllowMethods: []string{
http.MethodGet,
http.MethodPost,
},
AllowHeaders: []string{
"Content-Type",
"Authorization",
},
AllowCredentials: true,
}))
Types ¶
type CORSOptions ¶
type CORSOptions struct {
AllowOrigins []string
AllowMethods []string
AllowHeaders []string
ExposeHeaders []string
AllowCredentials bool
MaxAge int
}
CORSOptions configures Cross-Origin Resource Sharing (CORS) behavior for the CORS middleware.
Example:
app.Use(middleware.CORS(middleware.CORSOptions{
AllowOrigins: []string{"http://localhost:5173"},
AllowCredentials: true,
}))
func DefaultCORS ¶
func DefaultCORS() CORSOptions
DefaultCORS returns the default CORS configuration.
By default, all origins are allowed and common HTTP methods and headers are enabled.