content

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package content provides a versioned content-pack loader: a manifest- indexed bundle of typed entries that loads at boot, validates checksums, supports diffing across versions, and offers hot-reload for dev loops.

Domain-agnostic; common applications:

  • Game content (exported assets, level data, balance tables).
  • Strategy or ML config bundles shipped alongside code.
  • Static dataset releases consumed by data-driven services.

A pack is a directory (or .tar.gz archive) with a `manifest.json` describing the entries inside.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrManifestMissing = errors.New("content: manifest.json not found")
	ErrEntryMissing    = errors.New("content: entry not in manifest")
	ErrHashMismatch    = errors.New("content: entry SHA256 mismatch")
	ErrTypeMismatch    = errors.New("content: typed view requested wrong type")
)

Errors surfaced from this package.

Functions

This section is empty.

Types

type Builder

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

Builder constructs content packs.

func NewBuilder

func NewBuilder(id PackID, version Version) *Builder

NewBuilder returns a fresh Builder for the given pack id + version.

func (*Builder) AddFile

func (b *Builder) AddFile(path, typ string, data []byte)

AddFile records an entry's bytes under the given path with the given logical type. Overwrites if path already present.

func (*Builder) Build

func (b *Builder) Build(outDir string) (Manifest, error)

Build writes the pack contents (manifest + entries) under outDir.

type DiffReport

type DiffReport struct {
	Added    []string
	Removed  []string
	Modified []string
}

DiffReport summarises the changes between two Manifests.

func Diff

func Diff(old, new Manifest) DiffReport

Diff returns the entries added, removed, or changed (by SHA256) between old and new manifests.

type Entry

type Entry struct {
	Path   string `json:"path"`
	Type   string `json:"type"`
	SHA256 string `json:"sha256"`
	Size   int64  `json:"size"`
}

Entry is one file inside the pack.

type Loader

type Loader[T any] func(data []byte) (T, error)

Loader decodes raw entry bytes into a typed value of T.

type Manifest

type Manifest struct {
	Pack    PackID    `json:"pack"`
	Version Version   `json:"version"`
	BuiltAt time.Time `json:"built_at"`
	Entries []Entry   `json:"entries"`
}

Manifest describes the entries of a content pack.

type Pack

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

Pack is a loaded content pack on disk.

func Load

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

Load opens the pack rooted at path and reads its manifest. Entry bytes are loaded lazily on first Read.

func (*Pack) Manifest

func (p *Pack) Manifest() Manifest

Manifest returns the pack's manifest.

func (*Pack) Read

func (p *Pack) Read(entry string) ([]byte, error)

Read returns the entry's bytes, validating the SHA256 against the manifest on first read. Cached for subsequent reads.

func (*Pack) Reload

func (p *Pack) Reload() error

Reload re-reads the manifest from disk and invalidates the cache. Use during dev to pick up rebuilt packs without restart.

type PackID

type PackID string

PackID is the logical name of a pack ("warhammer-dungeons").

type TypedView

type TypedView[T any] struct {
	// contains filtered or unexported fields
}

TypedView provides typed access to the subset of pack entries of a given logical Type. Constructed once via TypedFor and reused for the pack's lifetime; cache misses load and decode lazily.

func TypedFor

func TypedFor[T any](p *Pack, typ string, loader Loader[T]) *TypedView[T]

TypedFor returns a TypedView over entries of the given logical Type (matching Manifest.Entries.Type) decoded via loader.

func (*TypedView[T]) All

func (v *TypedView[T]) All(yield func(path string, value T, err error) bool)

All enumerates every typed entry in the pack with its path. The yield function returns false to stop early.

func (*TypedView[T]) ByPath

func (v *TypedView[T]) ByPath(path string) (T, error)

ByPath loads and decodes the entry at path. Returns ErrEntryMissing if the path is not in the manifest, ErrTypeMismatch if the entry's Type differs from the view's Type.

type Version

type Version string

Version is a semver-ish string identifier ("1.4.2").

Directories

Path Synopsis
Package lint is the extensible content-pack lint surface.
Package lint is the extensible content-pack lint surface.

Jump to

Keyboard shortcuts

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