templating

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// PlaceholderRegex matches placeholder patterns like {word}
	PlaceholderRegex = regexp.MustCompile(`\{([A-Za-z0-9_\-]+)\}`)

	// EnvVarRegex matches environment variable naming pattern (uppercase letters, numbers, underscores)
	EnvVarRegex = regexp.MustCompile(`^[A-Z][A-Z0-9_]*$`)
)

Functions

func BuildDashboardBuiltins

func BuildDashboardBuiltins() map[string]string

BuildDashboardBuiltins returns the builtins map for dashboard path templates.

func BuildMonitorBuiltins

func BuildMonitorBuiltins() map[string]string

BuildMonitorBuiltins returns the builtins map for monitor path templates.

func ComputePathFromTemplate

func ComputePathFromTemplate(pattern string, data any) (string, error)

ComputePathFromTemplate executes a Go template to compute a file path. It handles template parsing and execution, returning an error if either fails. The pattern should already be translated (using TranslatePlaceholders). Returns the computed path, replacing "<no value>" with "none".

func ExtractStaticPrefix

func ExtractStaticPrefix(pathTemplate string) string

ExtractStaticPrefix returns the longest static prefix from a path template. For example, "data/dashboards/{id}.json" returns "data/dashboards". Environment variable placeholders (e.g., {MY_VAR}) and data are expanded before extraction. For example, if MY_BASE=/opt/data, then "{MY_BASE}/dashboards/{id}.json" returns "/opt/data/dashboards". This is used to determine the base directory to scan when updating existing files.

func ExtractTagMap

func ExtractTagMap(raw any, sanitize bool) map[string]string

ExtractTagMap converts a raw tags value (typically []any or []interface{}) into a map[key]value. If sanitize is true, values are sanitized via storage.SanitizeFilename.

func HasAllTagsMap

func HasAllTagsMap(tags map[string]string, filterTags []string) bool

HasAllTagsMap checks if tags contain all required filterTags (case-insensitive), where filterTags are in the form key:value.

func HasAllTagsSlice

func HasAllTagsSlice(dashboardTags []string, filterTags []string) bool

HasAllTagsSlice checks if all filterTags are present in dashboardTags (both lowercase for comparison).

func TranslatePlaceholders

func TranslatePlaceholders(pattern string, builtins map[string]string) string

TranslatePlaceholders converts placeholders like {id} into Go template expressions. Builtins should map placeholders (e.g. "{id}") to template expressions (e.g. "{{.ID}}"). Environment variable placeholders (e.g. {MY_VAR}) are replaced with their env var values first. Any remaining {word} will be mapped to {{.Tags.word}}.

Types

This section is empty.

Jump to

Keyboard shortcuts

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