Documentation
¶
Overview ¶
Package static is part of the GoFastr framework. See https://github.com/DonaldMurillo/gofastr for documentation.
Package static provides a static file server for Go's embed.FS (or any fs.FS), with ETag-based caching, configurable Cache-Control headers, MIME type detection, SPA fallback, and optional directory listing.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DetectFromName ¶
DetectFromName returns the MIME type for the given filename based on its extension. It first tries mime.TypeByExtension, then falls back to a built-in mapping, and finally returns "application/octet-stream" if no match is found.
func FingerprintURL ¶
FingerprintURL appends a content hash to the filename portion of the URL path for cache busting. For example:
FingerprintURL("/assets/app.js", "abc123") → "/assets/app.abc123.js"
Types ¶
type Config ¶
type Config struct {
// FS is the filesystem to serve files from (e.g. an embed.FS).
FS fs.FS
// Prefix is the URL path prefix to strip when mapping to filesystem paths.
// For example, with Prefix="/static", a request for "/static/app.js"
// serves "app.js" from FS.
Prefix string
// MaxAge is the default cache duration for Cache-Control headers.
// Zero means "no-cache".
MaxAge time.Duration
// IndexFile is the name of the default file to serve for directory paths.
// Defaults to "index.html".
IndexFile string
// SPA enables single-page application mode. When true, requests for
// paths that don't match any file will serve IndexFile instead of 404.
SPA bool
// DirListing is reserved for a future release.
// When implemented, enabling it will render an HTML directory listing
// instead of returning 404 for directory paths that lack an index file.
// Do not set this field — it is currently ignored.
DirListing bool
}
Config holds the configuration for serving static files.