Documentation
¶
Overview ¶
Package template provides utilities for Go template AST inspection and analysis. This package enables extraction of field references from templates, which is useful for dependency resolution (e.g., locals referencing other locals).
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExtractAllFieldRefsByPrefix ¶
ExtractAllFieldRefsByPrefix extracts all field references that start with a specific prefix, returning the full remaining path after the prefix. For example, ExtractAllFieldRefsByPrefix(tmpl, "locals") for .locals.config.nested returns ["config.nested"].
func ExtractFieldRefsByPrefix ¶
ExtractFieldRefsByPrefix extracts field references that start with a specific prefix. For example, ExtractFieldRefsByPrefix(tmpl, "locals") returns all .locals.X references. Returns the second-level identifiers (e.g., "foo" for .locals.foo).
func HasTemplateActions ¶
HasTemplateActions checks if a string contains Go template actions. This is a more robust version that uses AST parsing instead of simple string matching.
Types ¶
type FieldRef ¶
type FieldRef struct {
Path []string // e.g., ["locals", "foo"] for .locals.foo
}
FieldRef represents a reference to a field in a template (e.g., .locals.foo).
func ExtractFieldRefs ¶
ExtractFieldRefs parses a Go template string and extracts all field references. Handles complex expressions: conditionals, pipes, range, with blocks, nested templates. Returns nil if the string is not a valid template or contains no field references.