Documentation ¶
Index ¶
- Variables
- func AddLogger(logger request.Logger) router.Middleware
- func AddUserMiddleware(f func(*request.Request) request.User) router.Middleware
- func AllowContentType(contentTypes ...string) func(next router.Handler) router.Handler
- func AllowedHosts(allowed_hosts ...string) func(next router.Handler) router.Handler
- func Cache(maxAge int) func(next router.Handler) router.Handler
- func FormatMessage(r *request.Request, messageType string, format string, args ...any) string
- func GZIP(next router.Handler) router.Handler
- func LoginRequiredMiddleware(notAuth func(r *request.Request)) func(next router.Handler) router.Handler
- func LoginRequiredRedirectMiddleware(nextURL string) func(next router.Handler) router.Handler
- func LogoutRequiredMiddleware(isAuth func(r *request.Request)) func(next router.Handler) router.Handler
- func LogoutRequiredRedirectMiddleware(nextURL string) func(next router.Handler) router.Handler
- func NoCache(next router.Handler) router.Handler
- func PrinterFunc(next router.Handler, out io.Writer) router.Handler
- func RateLimiterMiddleware(conf *RateLimitOptions) func(next router.Handler) router.Handler
- func Recoverer(onError func(err error, r *request.Request)) router.Middleware
- func XFrameOptions(options XFrameOption) router.Middleware
- type RateLimitOptions
- type RateLimitType
- type XFrameOption
Constants ¶
This section is empty.
Variables ¶
var DEFAULT_LOGGER request.Logger
Functions ¶
func AddUserMiddleware ¶
Helper function to more easily add a user to the request.
func AllowContentType ¶
func AllowContentType(contentTypes ...string) func(next router.Handler) router.Handler
AllowContentType is a middleware that checks the content type of the request body. If the content type is not allowed, the middleware will return a http.StatusUnsupportedMediaType error.
func AllowedHosts ¶
func AllowedHosts(allowed_hosts ...string) func(next router.Handler) router.Handler
Check if the request.Host is in the allowed hosts list
func Cache ¶
func Cache(maxAge int) func(next router.Handler) router.Handler
Set the cache headers for the response. This will enable caching for the specified amount of seconds.
func FormatMessage ¶
Format the message, paired with the request IP and method.
func GZIP ¶
func GZIP(next router.Handler) router.Handler
GZIP compresses the response using gzip compression.
func LoginRequiredMiddleware ¶
func LoginRequiredMiddleware(notAuth func(r *request.Request)) func(next router.Handler) router.Handler
Middleware that only allows users who are authenticated to continue. By default, will call the notAuth function. Configure the AddUserMiddleware to change the default behavior.
func LoginRequiredRedirectMiddleware ¶
func LoginRequiredRedirectMiddleware(nextURL string) func(next router.Handler) router.Handler
Middleware that only allows users who are authenticated to continue. By default, will always redirect. Set the following function to change the default behavior: Configure the AddUserMiddleware to change the default behavior.
func LogoutRequiredMiddleware ¶
func LogoutRequiredMiddleware(isAuth func(r *request.Request)) func(next router.Handler) router.Handler
Middleware that only allows users who are not authenticated to continue By default, will never call the isAuth function. Set the following function to change the default behavior: Configure the AddUserMiddleware to change the default behavior.
func LogoutRequiredRedirectMiddleware ¶
func LogoutRequiredRedirectMiddleware(nextURL string) func(next router.Handler) router.Handler
Middleware that only allows users who are not authenticated to continue By default, will never call the isAuth function. Set the following function to change the default behavior: Configure the AddUserMiddleware to change the default behavior.
func NoCache ¶
func NoCache(next router.Handler) router.Handler
Set the cache headers for the response. This will disable caching.
func PrinterFunc ¶
func RateLimiterMiddleware ¶
func RateLimiterMiddleware(conf *RateLimitOptions) func(next router.Handler) router.Handler
Rate Limiter Middleware
func XFrameOptions ¶ added in v3.2.1
func XFrameOptions(options XFrameOption) router.Middleware
X-Frame-Options is a header that can be used to indicate whether or not a browser should be allowed to render a page in a <frame>, <iframe> or <object>.
Sites can use this to avoid clickjacking attacks, by ensuring that their content is not embedded into other sites.
Types ¶
type RateLimitOptions ¶
type RateLimitOptions struct { CookieName string Type RateLimitType RequestsPerSecond int BurstMultiplier int CleanExpiry time.Duration CleanInt time.Duration LimitHandler func(r *request.Request) }
RateLimitOptions is a struct that holds the options for the rate limiter.
type RateLimitType ¶
type RateLimitType int
Rate limit types.
const ( RateLimitIP RateLimitType = iota RateLimitIP_Proxy RateLimitCookie )
Rate limit types, used to determine what to rate limit with.
type XFrameOption ¶ added in v3.2.1
type XFrameOption string
XFrameOption is the type for the XFrameOptions middleware.
const ( // XFrameDeny is the most restrictive option, and it tells the browser to not display the content in an iframe. XFrameDeny XFrameOption = "DENY" // XFrameSame is the default value for XFrameOptions. XFrameSame XFrameOption = "SAMEORIGIN" // XFrameAllow is a special case, and it should not be used. // It is obsolete and is only here for backwards compatibility. XFrameAllow XFrameOption = "ALLOW-FROM" )