Documentation ¶
Overview ¶
Package station provides HTTP static file serving & caching middleware.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Cache ¶
func Cache(options ...CacheOption) func(http.Handler) http.Handler
Cache provides HTTP middleware for setting client-side caching headers for HTTP resources. These headers are commonly used to set far-future dates for static assets to minimise additional HTTP requests on repeat visits.
func Serve ¶
func Serve(dir string, options ...StaticOption) http.Handler
Serve is a handler that serves static files from the directory provided. If the file doesn't exist, it calls the currently configured NotFoundHandler (defaults to http.NotFoundHandler).
func Static ¶
Static provides HTTP middleware that serves static assets from the directory provided. If the file doesn't exist, it calls the wrapped handler/router. This is useful when you want static files in a directory to be served as a first priority (e.g. favicon.ico, stylesheets, etc.) across an entire router.
Types ¶
type CacheOption ¶
type CacheOption func(*cache)
CacheOption represents an option for configuring the Cache handler.
func MaxAge ¶
func MaxAge(age int64) CacheOption
MaxAge sets the duration to cache objects for in seconds.
type StaticOption ¶
type StaticOption func(*static)
StaticOption represents an option for configuring the Static and Server handlers.
func NotFoundHandler ¶
func NotFoundHandler(h http.Handler) StaticOption
NotFoundHandler sets a custom http.Handler to be called when using the Serve handler. Set this to serve 'pretty' HTTP 404 pages or re-directs. elsewhere.