assets

package
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: May 24, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package assets provides runtime resolution of fingerprinted asset paths.

During the build process, Vango generates a manifest.json mapping source asset names to their fingerprinted (hashed) versions:

{
  "vango.js": "vango.a1b2c3d4.min.js",
  "styles.css": "styles.e5f6g7h8.css"
}

This package loads that manifest and provides resolution functions for use in templates and components:

manifest, _ := assets.Load("dist/manifest.json")
resolver := assets.NewResolver(manifest, "/public/")

// In component:
Script(Src(ctx.Asset("vango.js")))
// Outputs: <script src="/public/vango.a1b2c3d4.min.js">

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Manifest

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

Manifest holds the mapping from source asset paths to fingerprinted paths. It is safe for concurrent use.

func Load

func Load(path string) (*Manifest, error)

Load reads a manifest.json file and returns a Manifest. The manifest file is expected to be in JSON format: {"source.js": "source.abc123.js"}

If the file does not exist or cannot be read, an error is returned. In development, you may want to ignore the error and use NewPassthroughResolver.

func NewManifest

func NewManifest() *Manifest

NewManifest creates an empty manifest. Use Load() to create a manifest from a JSON file.

func (*Manifest) All

func (m *Manifest) All() map[string]string

All returns a copy of all manifest entries.

func (*Manifest) Has

func (m *Manifest) Has(source string) bool

Has returns true if the manifest contains the given source path.

func (*Manifest) Len

func (m *Manifest) Len() int

Len returns the number of entries in the manifest.

func (*Manifest) Resolve

func (m *Manifest) Resolve(source string) string

Resolve returns the fingerprinted path for the given source path. If not found, returns the original path unchanged.

This is the core resolution function. For most use cases, prefer using a Resolver with a configured prefix.

func (*Manifest) Set

func (m *Manifest) Set(source, resolved string)

Set adds or updates an entry in the manifest. This is primarily useful for testing or dynamic manifest building.

type Resolver

type Resolver interface {
	// Asset resolves a source asset path to its full URL path.
	// This includes any configured prefix and fingerprinted filename.
	//
	// Example:
	//   resolver.Asset("vango.js") → "/public/vango.a1b2c3d4.min.js"
	Asset(source string) string
}

Resolver provides asset path resolution. It combines manifest lookup with path prefixing.

func NewPassthroughResolver

func NewPassthroughResolver(prefix string) Resolver

NewPassthroughResolver creates a resolver that returns paths unchanged. Use this in development mode where fingerprinting is disabled.

The prefix is still applied, so dev and prod paths remain consistent:

// Development:
resolver := assets.NewPassthroughResolver("/public/")
resolver.Asset("vango.js") // "/public/vango.js"

// Production:
resolver := assets.NewResolver(manifest, "/public/")
resolver.Asset("vango.js") // "/public/vango.a1b2c3d4.min.js"

func NewResolver

func NewResolver(m *Manifest, prefix string) Resolver

NewResolver creates a Resolver from a Manifest with an optional path prefix.

The prefix is prepended to all resolved paths. Common prefixes:

  • "/public/" - standard static file path
  • "/assets/" - alternative static path
  • "" - no prefix (use fingerprinted name directly)

Example:

manifest, _ := assets.Load("dist/manifest.json")
resolver := assets.NewResolver(manifest, "/public/")
resolver.Asset("vango.js") // "/public/vango.a1b2c3d4.min.js"

Jump to

Keyboard shortcuts

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