assets

package
v0.176.0 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2026 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetPath

func GetPath(ctx context.Context, logical string) string

GetPath returns the hashed, servable path for a logical asset name. Use this from templ templates: assets.GetPath(m, "scripts.js") -> "/assets/scripts.a1b2c3d4.js"

If the asset isn't found, it logs and returns the logical name unchanged so a missed rename fails loudly (404) rather than silently breaking the page.

func HandleAssets

func HandleAssets(urlPrefix string, unHashed bool) http.Handler

HandleAssets returns an http.Handler that serves assets at urlPrefix. Hashed paths (the normal case) get long-lived immutable caching. Unhashed/unknown paths fall through with no special caching, which lets you 404 cleanly or serve other static files from the same prefix if needed.

func New

func New(fsys fs.FS, root string) error

New walks fsys, computes a short content hash for every regular file, and returns a Manifest you can use to both build asset URLs and serve them.

root, if non-empty, is stripped as a prefix when building logical paths (useful if your embed.FS embeds "web/content" but you want asset paths like "scripts.js" rather than "web/content/scripts.js").

Types

type Manifest

type Manifest struct {
	// contains filtered or unexported fields
}

Manifest maps a logical asset path ("scripts.js") to its hashed, servable path ("scripts.a1b2c3d4.js"). Build it once at startup with New.

Jump to

Keyboard shortcuts

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