Documentation
¶
Overview ¶
Package middleware contains HTTP middleware used by the Plank server.
Index ¶
- func BasicSecurityHeaderMiddleware() routing.MiddlewareFunc
- func CacheControlMiddleware(globPatterns []string, directive *CacheControlDirective) routing.MiddlewareFunc
- type CacheControlDirective
- func (c *CacheControlDirective) Immutable() *CacheControlDirective
- func (c *CacheControlDirective) MaxAge(t time.Duration) *CacheControlDirective
- func (c *CacheControlDirective) MaxStale(t time.Duration) *CacheControlDirective
- func (c *CacheControlDirective) MinFresh(t time.Duration) *CacheControlDirective
- func (c *CacheControlDirective) MustRevalidate() *CacheControlDirective
- func (c *CacheControlDirective) NoCache() *CacheControlDirective
- func (c *CacheControlDirective) NoStore() *CacheControlDirective
- func (c *CacheControlDirective) NoTransform() *CacheControlDirective
- func (c *CacheControlDirective) OnlyIfCached() *CacheControlDirective
- func (c *CacheControlDirective) Private() *CacheControlDirective
- func (c *CacheControlDirective) ProxyRevalidate() *CacheControlDirective
- func (c *CacheControlDirective) Public() *CacheControlDirective
- func (c *CacheControlDirective) SharedMaxAge(t time.Duration) *CacheControlDirective
- func (c *CacheControlDirective) String() string
- type CacheControlRulePair
- type Middleware
- type MiddlewareManager
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BasicSecurityHeaderMiddleware ¶
func BasicSecurityHeaderMiddleware() routing.MiddlewareFunc
BasicSecurityHeaderMiddleware adds the default Plank security headers.
func CacheControlMiddleware ¶
func CacheControlMiddleware(globPatterns []string, directive *CacheControlDirective) routing.MiddlewareFunc
CacheControlMiddleware is the middleware function to be provided as a parameter to a route handler.
Types ¶
type CacheControlDirective ¶
type CacheControlDirective struct {
// contains filtered or unexported fields
}
CacheControlDirective is a data structure that represents the entry for Cache-Control rules
func NewCacheControlDirective ¶
func NewCacheControlDirective() *CacheControlDirective
NewCacheControlDirective returns creates a new instance of CacheControlDirective and returns its pointer
func (*CacheControlDirective) Immutable ¶
func (c *CacheControlDirective) Immutable() *CacheControlDirective
Immutable adds the immutable directive.
func (*CacheControlDirective) MaxAge ¶
func (c *CacheControlDirective) MaxAge(t time.Duration) *CacheControlDirective
MaxAge adds the max-age directive using t in seconds.
func (*CacheControlDirective) MaxStale ¶
func (c *CacheControlDirective) MaxStale(t time.Duration) *CacheControlDirective
MaxStale adds the max-stale directive using t in seconds.
func (*CacheControlDirective) MinFresh ¶
func (c *CacheControlDirective) MinFresh(t time.Duration) *CacheControlDirective
MinFresh adds the min-fresh directive using t in seconds.
func (*CacheControlDirective) MustRevalidate ¶
func (c *CacheControlDirective) MustRevalidate() *CacheControlDirective
MustRevalidate adds the must-revalidate directive.
func (*CacheControlDirective) NoCache ¶
func (c *CacheControlDirective) NoCache() *CacheControlDirective
NoCache adds the no-cache directive.
func (*CacheControlDirective) NoStore ¶
func (c *CacheControlDirective) NoStore() *CacheControlDirective
NoStore adds the no-store directive.
func (*CacheControlDirective) NoTransform ¶
func (c *CacheControlDirective) NoTransform() *CacheControlDirective
NoTransform adds the no-transform directive.
func (*CacheControlDirective) OnlyIfCached ¶
func (c *CacheControlDirective) OnlyIfCached() *CacheControlDirective
OnlyIfCached adds the only-if-cached directive.
func (*CacheControlDirective) Private ¶
func (c *CacheControlDirective) Private() *CacheControlDirective
Private adds the private cache directive.
func (*CacheControlDirective) ProxyRevalidate ¶
func (c *CacheControlDirective) ProxyRevalidate() *CacheControlDirective
ProxyRevalidate adds the proxy-revalidate directive.
func (*CacheControlDirective) Public ¶
func (c *CacheControlDirective) Public() *CacheControlDirective
Public adds the public cache directive.
func (*CacheControlDirective) SharedMaxAge ¶
func (c *CacheControlDirective) SharedMaxAge(t time.Duration) *CacheControlDirective
SharedMaxAge adds the s-maxage directive using t in seconds.
func (*CacheControlDirective) String ¶
func (c *CacheControlDirective) String() string
type CacheControlRulePair ¶
type CacheControlRulePair struct {
GlobPattern string
CacheControlRule string
CompiledGlobPattern glob.Glob
}
CacheControlRulePair is a container that lumps together the glob pattern, cache control rule that should be applied to for the matching pattern and the compiled glob pattern for use in runtime. see https://github.com/gobwas/glob for detailed examples of glob patterns.
func NewCacheControlRulePair ¶
func NewCacheControlRulePair(globPattern string, cacheControlRule string) (CacheControlRulePair, error)
NewCacheControlRulePair returns a new CacheControlRulePair with the provided text glob pattern and its compiled counterpart and the cache control rule.
type Middleware ¶
type Middleware interface {
// Intercept(h http.Handler) http.Handler
Interceptor() routing.MiddlewareFunc
Name() string
}
Middleware names a routing middleware interceptor.
type MiddlewareManager ¶
type MiddlewareManager interface {
SetGlobalMiddleware(middleware []routing.MiddlewareFunc) error
SetNewMiddleware(route *routing.Route, middleware []routing.MiddlewareFunc) error
RemoveMiddleware(route *routing.Route) error
GetRouteByUriAndMethod(uri, method string) (*routing.Route, error)
GetRouteByUri(uri string) (*routing.Route, error)
GetStaticRoute(prefix string) (*routing.Route, error)
}
MiddlewareManager manages route-specific and global HTTP middleware.
func NewMiddlewareManager ¶
func NewMiddlewareManager(endpointHandlerMapPtr *map[string]http.HandlerFunc, router *routing.Router, logger *slog.Logger) MiddlewareManager
NewMiddlewareManager sets up a new middleware manager singleton instance