render

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2026 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const Timeout = 10 * time.Second

Variables

This section is empty.

Functions

func ExtractEnvVars

func ExtractEnvVars(name string, cfg *config.FileConfig) map[string]bool

ExtractEnvVars parses the template referenced by cfg and walks its AST to find all statically-referenced environment variable names (via env "KEY" and envDefault "KEY" "fallback" calls). Returns the set of referenced var names, or nil on any error (parse failure, missing template, command mode) as a "keep all env" fallback.

func FilterEnv

func FilterEnv(name string, cfg *config.FileConfig, env map[string]string) map[string]string

FilterEnv returns a filtered copy of env containing only the variables referenced by cfg's template. Returns nil if env is nil (global layer). For command-mode files, returns only the allowlist vars (PATH, HOME, etc.) since referenced variables cannot be statically extracted. Returns the original env unchanged if extraction fails (safe fallback).

Types

type CommandRenderer

type CommandRenderer struct{}

func (*CommandRenderer) Render

func (r *CommandRenderer) Render(
	_ string,
	cfg *config.FileConfig,
	_ EnvLookup,
	envOverrides map[string]string,
) ([]byte, error)

type EnvLookup

type EnvLookup func(string) (string, bool)

EnvLookup resolves environment variables. nil means os.LookupEnv.

type NativeRenderer

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

NativeRenderer uses Go's text/template with sprout functions and custom builtins: env, envDefault, file, exec. Parsed template texts are cached so that repeated renders (e.g. FUSE open()) skip disk I/O and re-parsing. The cache is invalidated when the template file's mtime changes.

func (*NativeRenderer) Render

func (r *NativeRenderer) Render(
	name string,
	cfg *config.FileConfig,
	envLookup EnvLookup,
	envOverrides map[string]string,
) ([]byte, error)

type TemplateRenderer

type TemplateRenderer interface {
	Render(
		name string,
		cfg *config.FileConfig,
		envLookup EnvLookup,
		envOverrides map[string]string,
	) ([]byte, error)
}

func NewRenderer

func NewRenderer(fc *config.FileConfig) TemplateRenderer

type Watcher

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

Watcher watches template files and calls a callback when any change.

func NewWatcher

func NewWatcher(onChange func()) (*Watcher, error)

NewWatcher creates a template file watcher. onChange is called (at most once per event batch) when any watched template changes on disk.

func (*Watcher) Close

func (w *Watcher) Close() error

func (*Watcher) Run

func (w *Watcher) Run()

func (*Watcher) Unwatch

func (w *Watcher) Unwatch(path string)

Unwatch removes a path from watching.

func (*Watcher) Watch

func (w *Watcher) Watch(path string)

Watch adds a template path to be watched. Duplicate calls are ignored.

func (*Watcher) WatchWithCallback

func (w *Watcher) WatchWithCallback(path string, cb func())

WatchWithCallback watches a path with a per-path callback instead of the default onChange. Watches the parent directory to handle atomic saves.

Jump to

Keyboard shortcuts

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