Documentation
¶
Overview ¶
Package asset serves a bounded set of application assets from an fs.FS.
Set validates and reads every file at construction time. Requests therefore never touch the source filesystem, and callers can replace Set with any ordinary http.Handler and URL resolver when local embedding no longer fits.
Index ¶
Constants ¶
const ( // DefaultMaxFiles is the zero-config inventory limit. DefaultMaxFiles = 256 // DefaultMaxFileBytes is the zero-config per-file limit. DefaultMaxFileBytes int64 = 8 << 20 // DefaultMaxTotalBytes is the zero-config total inventory limit. DefaultMaxTotalBytes int64 = 32 << 20 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
Root string
// URLPrefix is an absolute, canonical path without a trailing slash. It
// defaults to /assets.
URLPrefix string
MaxFiles int
MaxFileBytes int64
MaxTotalBytes int64
}
Config describes one immutable in-memory asset set. Zero limits select conservative defaults: 256 files, 8 MiB per file, and 32 MiB total.
type Set ¶
type Set struct {
// contains filtered or unexported fields
}
Set is a validated collection of application-owned assets. It is safe for concurrent use after New returns.
func New ¶
New validates root and reads its complete file inventory into a Set. Directories and filenames must use portable, canonical paths. HTML, SVG, XML, and other unlisted types are rejected instead of being served as same-origin active content or relying on platform MIME databases.
func (*Set) ServeHTTP ¶
func (set *Set) ServeHTTP(response http.ResponseWriter, request *http.Request)
ServeHTTP serves GET and HEAD requests below the configured URL prefix. Successful representations always use strong SHA-256 validators and require cache revalidation. http.ServeContent supplies standard conditional and byte range semantics over the immutable in-memory bytes.