resources

package
v0.5.52 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2026 License: MIT Imports: 9 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package resources gives a scene a namespace for its files.

An application ships a resources/ directory next to its main package:

//go:embed all:resources
var appFS embed.FS

bundle := resources.New()
bundle.Mount("res", appFS, "resources")
scene, _ := view.LoadBundle(bundle, "res://scenes/main.qml", ...)

QML then refers to files as res://images/hero.png. The toolkit's own defaults (fonts, themes) live in the meui:// namespace. External directories can be mounted over either namespace at runtime, so an app can read a theme from disk without giving up the bundled defaults; the mount decides whether the external copy or the bundled one wins.

Every name is a slash-separated path inside a mount. Absolute paths and ".." are refused, so a scene cannot escape its bundle. External mounts go through os.Root, which refuses symlinks that leave the mounted directory.

Index

Constants

This section is empty.

Variables

View Source
var ErrNoScheme = errors.New("resources: URI has no scheme")

ErrNoScheme means the URI does not start with "<scheme>://".

Functions

func IsURI

func IsURI(s string) bool

IsURI reports whether s is a resource URI. Any "<scheme>://" counts except the network and file schemes, which are not bundles: http(s) stays the renderer's clear "remote images are not fetched" error, and file:// is a disk path.

func Open

func Open(uri string) (fs.File, error)

Open opens from the default bundle.

func ReadFile

func ReadFile(uri string) ([]byte, error)

ReadFile reads from the default bundle.

func ReadFileLimit

func ReadFileLimit(uri string, limit int64) ([]byte, error)

ReadFileLimit reads from the default bundle with a byte cap.

func RegisterBuiltin

func RegisterBuiltin(fsys fs.FS)

RegisterBuiltin mounts fsys at meui://. It is called by the meui package's init from its embedded files; a no_embed build registers nothing.

func Use

func Use(b *Bundle)

Use makes b the process-wide bundle. Call it before creating scenes or windows; most apps mount on Default() instead and never need this.

Types

type Bundle

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

Bundle is a set of namespaces. The zero value is not usable; call New.

func Default

func Default() *Bundle

Default returns the process-wide bundle the widgets resolve URIs against.

func New

func New() *Bundle

New returns an empty bundle.

func (*Bundle) Exists

func (b *Bundle) Exists(uri string) bool

Exists reports whether uri names a regular file in any layer.

func (*Bundle) Mount

func (b *Bundle) Mount(scheme string, fsys fs.FS, root string) error

Mount installs fsys at scheme, rooted at root inside fsys. Mounting a scheme again replaces its layers.

func (*Bundle) MountExternal

func (b *Bundle) MountExternal(scheme, dir string) error

MountExternal adds an external directory as a layer of scheme. The layer is embedded-first unless SetOrder makes it external-first. The directory must exist.

func (*Bundle) Open

func (b *Bundle) Open(uri string) (fs.File, error)

Open opens a resource URI. Directories are openable too; callers that need a file should Stat it.

func (*Bundle) ReadDir

func (b *Bundle) ReadDir(uri string) ([]fs.DirEntry, error)

ReadDir merges the layers. The higher-precedence layer wins on a duplicate name; the result is sorted by name so a theme list is stable.

func (*Bundle) ReadFile

func (b *Bundle) ReadFile(uri string) ([]byte, error)

ReadFile reads a regular file. It is capped so a bad name cannot exhaust memory; callers that keep the bytes apply their own tighter limits.

func (*Bundle) ReadFileLimit

func (b *Bundle) ReadFileLimit(uri string, limit int64) ([]byte, error)

ReadFileLimit reads a regular file no larger than limit bytes.

func (*Bundle) Resolve

func (b *Bundle) Resolve(sceneURI, ref string) (string, bool)

Resolve turns a reference found in a scene into a resource URI. An explicit scheme is returned unchanged (and checked). A relative reference is tried against the scene's directory first, then against the bundle root.

func (*Bundle) SetOrder

func (b *Bundle) SetOrder(scheme string, order Order) error

SetOrder moves every external layer before the embedded ones (or after).

func (*Bundle) Stat

func (b *Bundle) Stat(uri string) (fs.FileInfo, error)

Stat reports the first matching entry.

func (*Bundle) Unmount

func (b *Bundle) Unmount(scheme string)

Unmount removes a scheme. It is mainly for tests that mount a fixture.

type Order

type Order int

Order selects which layer wins when a name exists in both the embedded mount and an external one. The zero value is the production-safe default.

const (
	// EmbeddedFirst lets the bundle shadow external files (default).
	EmbeddedFirst Order = iota
	// ExternalFirst lets an external directory shadow the bundle (development,
	// user-installed themes).
	ExternalFirst
)

Jump to

Keyboard shortcuts

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