embed

package
v0.104.0 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: Apache-2.0 Imports: 19 Imported by: 0 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.

README

@embed static assets

@embed accepts either one regular file or a directory under an explicitly configured filesystem root:

@require github.com/nexssp/flow/extensions/embed { root: "." }
@embed logo "assets/logo.svg"
@embed web "web/dist"

A single file remains a typed xfile.Ref. It is opened through the registered resolver, which requires caller and tenant scope and rechecks the digest and size. Passing it to actions still uses the normal typed ( ... ) argument form.

A directory becomes an embed.web map of slash-separated paths relative to the selected directory to []byte contents. This is intended for explicit public build output, such as a frontend folder; do not point it at a source tree, repository root, or directory containing secrets. Directory bytes are included in compile metadata and are available to ordinary actions such as thttp.static; they do not pass through the scoped file resolver.

Defaults bound each file to 16 MiB, the whole directory to 64 MiB, and the number of files to 4,096. The @require options max_size, max_total_size, and max_files set positive integer limits. For example:

@require github.com/nexssp/flow/extensions/embed {
  root: ".",
  max_size: "2097152",
  max_total_size: "16777216",
  max_files: "512"
}
@embed web "web/dist"

thttp.static accepts the directory as files: embed.web from a :raw_route pipeline. Its default index is index.html; spa: true falls back to the index only for extensionless paths, while missing assets with an extension remain 404 responses.

Directory handling is covered by nflows/directory_embed.nflow, executed in TestDirectoryEmbedNFlowFixture with a host-supplied virtual filesystem. The file-only reference and scoped resolver behavior remain covered by the existing embed tests.

Documentation

Overview

Package embed compiles static @embed declarations to typed file references or bounded directory asset maps.

Index

Constants

View Source
const (
	DefaultMaxTotalBytes = int64(64 << 20)
	DefaultMaxFiles      = 4096
)
View Source
const (
	ID              = "embed"
	DefaultProvider = "flow.static"
	DefaultMaxBytes = int64(16 << 20)
)

Variables

This section is empty.

Functions

func Bundle

func Bundle(opts map[string]string) compiler.Bundle

Bundle creates the standard extension bundle. The optional "root" setting names a filesystem directory and "provider" selects the xfile provider label. "max_size" bounds each file, while "max_total_size" and "max_files" bound directory embeds. No implicit process working-directory root is used.

func NewBundle

func NewBundle(fsys fs.FS, provider string, maxBytes int64) compiler.Bundle

NewBundle binds the directive to an explicitly declared fs.FS root. This is the preferred integration point for embedded or otherwise sandboxed filesystems.

Types

type AssetDirectory added in v0.103.0

type AssetDirectory = map[string][]byte

AssetDirectory maps slash-separated paths relative to the embedded directory to their file bytes.

type Resolver

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

Resolver serves only assets declared during preprocessing. References are mapped through opaque IDs to validated relative paths and are integrity-checked on every open; bytes are bounded by maxBytes and are not retained.

func BundleWithFileResolver

func BundleWithFileResolver(fsys fs.FS, provider string, maxBytes int64) (compiler.Bundle, *Resolver)

BundleWithFileResolver returns an embed bundle and its FS-backed resolver. The bundle registers the resolver so runner.BuildConfig composes it with other provider bindings automatically.

func (*Resolver) Open

func (r *Resolver) Open(ctx context.Context, ref xfile.Ref) (io.ReadCloser, xfile.Info, error)

Jump to

Keyboard shortcuts

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