GitHubEmpezar

La referencia de API proviene de los comentarios de documentación de Go en el código fuente y está redactada en inglés.

package manifest

import "github.com/nsgo-dev/game/pkg/tooling/manifest"

Resumen

Package manifest walks an assets directory and generates a typed Go source file referencing every asset, so missing or removed assets fail the build at compile time.

Índice

Funciones

func Generate(dir string, opts Options) ([]byte, error)

Generate scans dir and returns a gofmt-formatted Go source file declaring typed references for every asset in dir.

func Verify(dir string, refs []string) error

Verify checks that every asset reference in refs exists as a regular file under dir. Each ref may be a relative path ("hero.png") or an "asset:" URI ("asset:hero.png").

func WriteFile(dir, outPath string, opts Options) error

WriteFile generates the manifest for dir and writes it to outPath, creating parent directories if needed.

Tipos

type Entry struct {
	// Path is the asset's slash-separated path relative to the scanned directory.
	Path string
	// URI is the asset's URI with the configured prefix, such as "asset:hero.png".
	URI string
	// Ident is the exported Go identifier generated for this asset, such as "ImageHero".
	Ident string
	// Kind is the asset's classified type.
	Kind Kind
}

Entry is one asset file discovered in the assets directory.

func Scan(dir string, opts Options) ([]Entry, error)

Scan walks dir deterministically, skipping dot-prefixed entries, Go source files and import settings sidecars (files named *.import.yaml, as package importsettings names them), and returns the discovered asset entries sorted by Path with unique Go identifiers.

type Kind int

Kind classifies a discovered asset file by its extension.

const (
	// KindOther is any asset that is not an image, audio or map file.
	KindOther Kind = iota
	// KindImage is an image file exposed as a core.ImageSource.
	KindImage
	// KindAudio is an audio file exposed as an audio.Source.
	KindAudio
	// KindMap is a tilemap file (.tmj, .tmx, .tsj, .tsx).
	KindMap
)
func (k Kind) String() string

String returns the kind's name.

type Options struct {
	// Package is the generated Go file's package name ("assets" when empty).
	Package string
	// Prefix is prepended to each asset's relative path to form its URI ("asset:" when empty).
	Prefix string
	// Embed emits //go:embed directives so asset bytes are compiled into the binary instead of referencing URIs.
	Embed bool
	// EmbedDir is an optional slash-separated directory prefix prepended to each //go:embed pattern, for when the generated file lives in a parent of the assets directory.
	EmbedDir string
	// Header is the comment line at the top of the generated file (a standard generated-file notice when empty).
	Header string
}

Options configures asset scanning and Go source generation.

func DefaultOptions() Options

DefaultOptions returns Options with the generator's defaults: package "assets", URI prefix "asset:" and URI mode.