middleware

package
v0.9.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 29, 2026 License: BSD-2-Clause Imports: 8 Imported by: 0

Documentation

Overview

Package middleware contains HTTP middleware used by the Plank server.

Index

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

Immutable adds the immutable directive.

func (*CacheControlDirective) MaxAge

MaxAge adds the max-age directive using t in seconds.

func (*CacheControlDirective) MaxStale

MaxStale adds the max-stale directive using t in seconds.

func (*CacheControlDirective) MinFresh

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

NoCache adds the no-cache directive.

func (*CacheControlDirective) NoStore

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

Private adds the private cache directive.

func (*CacheControlDirective) ProxyRevalidate

func (c *CacheControlDirective) ProxyRevalidate() *CacheControlDirective

ProxyRevalidate adds the proxy-revalidate directive.

func (*CacheControlDirective) Public

Public adds the public cache directive.

func (*CacheControlDirective) SharedMaxAge

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL