Documentation
¶
Index ¶
- func CELKeywords() []string
- func CompileEnvOptions(environment map[string]any, template Template) []cel.EnvOption
- func CreateFuncs(ctx context.Context) template.FuncMap
- func GetCelEnv(environment map[string]any) []cel.EnvOption
- func IsCelKeyword(key string) bool
- func IsValidCELIdentifier(s string) bool
- func LoadSharedLibrary(source string) error
- func RegisterType(value any) error
- func RunExpression(environment map[string]any, template Template) (any, error)
- func RunExpressionContext(ctx commonsContext.Context, environment map[string]any, template Template) (any, error)
- func RunTemplate(environment map[string]any, template Template) (string, error)
- func RunTemplateBool(environment map[string]any, template Template) (bool, error)
- func RunTemplateContext(ctx commonsContext.Context, environment map[string]any, template Template) (string, error)
- func Serialize(in map[string]any) (out map[string]any, err error)
- func WithCELTracker(ctx commonsContext.Context, tracker *CELTracker) commonsContext.Context
- type AsMapper
- type CELTraceSnapshot
- type CELTracker
- type Delims
- type MetricsType
- type StructTemplater
- type Template
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CELKeywords ¶ added in v3.24.89
func CELKeywords() []string
CELKeywords returns the reserved words, sorted. Editor tooling needs the set itself, not just membership tests.
func CompileEnvOptions ¶ added in v3.24.89
CompileEnvOptions returns the options RunExpressionContext will compile the template against: the static set plus the per-call variables, registered native types, Functions and CelEnvs.
For callers that want to compile an expression themselves before running it, to get a source position out of the issues -- which RunExpression's error does not carry. Building that environment from GetCelEnv alone reports a template's own Functions and CelEnvs as undeclared references.
func CreateFuncs ¶
CreateFuncs - function mappings are created here
func GetCelEnv ¶ added in v3.20.19
GetCelEnv returns the full set of CEL env options: the static options, any types registered via RegisterType, and one variable per environment key.
RunExpressionContext no longer uses this on the hot path; it compiles against the cached base environment (baseCelEnv) and layers the per-call options with Env.Extend. GetCelEnv is retained for external callers and shares the static option set via staticCelEnvOptions.
func IsCelKeyword ¶ added in v3.24.54
IsCelKeyword returns true if the given key is a reserved word in Cel
func IsValidCELIdentifier ¶ added in v3.24.54
func LoadSharedLibrary ¶ added in v3.20.4
LoadSharedLibrary loads a shared library for Otto
func RegisterType ¶ added in v3.20.24
RegisterType makes a Go or CEL type available to subsequent CEL evaluations.
func RunExpression ¶ added in v3.20.19
func RunExpressionContext ¶ added in v3.24.30
func RunTemplate ¶ added in v3.20.4
func RunTemplateBool ¶ added in v3.24.33
func RunTemplateContext ¶ added in v3.24.30
func Serialize ¶ added in v3.20.19
Serialize iterates over each key-value pair in the input map serializes any struct value to map[string]any.
func WithCELTracker ¶ added in v3.24.85
func WithCELTracker(ctx commonsContext.Context, tracker *CELTracker) commonsContext.Context
WithCELTracker enables native CEL state tracking for evaluations using ctx.
Types ¶
type CELTraceSnapshot ¶ added in v3.24.85
CELTraceSnapshot exposes cel-go's native syntax and evaluation state for one completed evaluation. It is empty when compilation fails.
type CELTracker ¶ added in v3.24.85
type CELTracker struct {
// contains filtered or unexported fields
}
CELTracker captures native CEL evaluation state when attached to a context. A tracker may be reused sequentially, but not concurrently.
func NewCELTracker ¶ added in v3.24.85
func NewCELTracker() *CELTracker
NewCELTracker creates an opt-in native CEL evaluation tracker.
func (*CELTracker) Snapshot ¶ added in v3.24.85
func (t *CELTracker) Snapshot() CELTraceSnapshot
type MetricsType ¶
type MetricsType struct {
// times for rendering each template
RenderDuration map[string]time.Duration
// time it took to gather templates
GatherDuration time.Duration
// time it took to render all templates
TotalRenderDuration time.Duration
TemplatesGathered int
TemplatesProcessed int
Errors int
}
MetricsType - Warning: experimental! This may change in breaking ways without warning. This is not subject to any semantic versioning guarantees!
var Metrics *MetricsType
Metrics tracks interesting basic metrics around gomplate executions. Warning: experimental! This may change in breaking ways without warning. This is not subject to any semantic versioning guarantees!
type StructTemplater ¶ added in v3.20.23
type StructTemplater struct {
Context context.Context
Values map[string]interface{}
// IgnoreFields from walking where key is field name and value is field type
IgnoreFields map[string]string
Funcs map[string]any
DelimSets []Delims
// If specified create a function for each value so that is can be accessed via {{ value }} in addition to {{ .value }}
ValueFunctions bool
RequiredTag string
}
func (StructTemplater) Struct ¶ added in v3.20.23
func (w StructTemplater) Struct(reflect.Value) error
this func is required to fulfil the reflectwalk.StructWalker interface
func (StructTemplater) StructField ¶ added in v3.20.23
func (w StructTemplater) StructField(f reflect.StructField, v reflect.Value) error
func (StructTemplater) Template ¶ added in v3.20.23
func (w StructTemplater) Template(val string) (string, error)
func (StructTemplater) Walk ¶ added in v3.20.23
func (w StructTemplater) Walk(object interface{}) error
type Template ¶ added in v3.20.4
type Template struct {
Template string `yaml:"template,omitempty" json:"template,omitempty"` // Go template
JSONPath string `yaml:"jsonPath,omitempty" json:"jsonPath,omitempty"`
Expression string `yaml:"expr,omitempty" json:"expr,omitempty"` // A cel-go expression
Javascript string `yaml:"javascript,omitempty" json:"javascript,omitempty"`
RightDelim string `yaml:"-" json:"-"`
LeftDelim string `yaml:"-" json:"-"`
// DelimSets, when non-empty, runs the gotemplate over the input once per
// delimiter pair, feeding the output of each pass into the next. Useful for
// inputs that mix delimiter styles (e.g. {{ }} and $( )).
// A header (# gotemplate: left-delim=… right-delim=…) overrides DelimSets to
// a single pass. Falls back to LeftDelim/RightDelim if both are set, otherwise
// to the default {{ }}.
DelimSets []Delims `yaml:"-" json:"-"`
// ValueFunctions, when true, exposes each key in the environment as a
// zero-arg function in addition to dot-access. Enables {{ foo }} alongside
// the standard {{ .foo }}.
ValueFunctions bool `yaml:"-" json:"-"`
// Pass in additional cel-env options like functions
// that aren't simple enough to be included in Functions
CelEnvs []cel.EnvOption `yaml:"-" json:"-"`
// A map of functions that are accessible to cel expressions
// and go templates.
// NOTE: For cel expressions, the functions must be of type func() any.
// If any other function type is used, an error will be returned.
// Opt to CelEnvs for those cases.
Functions map[string]any `yaml:"-" json:"-"`
// CacheKey, when non-empty, is used as the program-cache key for this
// template, bypassing the IsCacheable() heuristic. The caller asserts that
// any two templates sharing this key may share the compiled cel.Program
// (same expression semantics, same env shape, same function semantics).
CacheKey string `yaml:"-" json:"-"`
// CacheTime controls how long the compiled program/template is retained
// in the cache. Zero means use the cache's default TTL; a positive value
// is an explicit TTL; a negative value means no expiration.
CacheTime time.Duration `yaml:"-" json:"-"`
}
func (Template) IsCacheable ¶ added in v3.24.0
func (Template) ShortString ¶ added in v3.24.30
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package base64 contains Base64 encoding/decoding functions
|
Package base64 contains Base64 encoding/decoding functions |
|
ceval
command
|
|
|
genmonarch
command
Command genmonarch generates the Monaco language definitions for the expression languages gomplate evaluates.
|
Command genmonarch generates the Monaco language definitions for the expression languages gomplate evaluates. |
|
playground
command
Command playground serves the evaluation API behind the language playground.
|
Command playground serves the evaluation API behind the language playground. |
|
Package coll contains functions to help manipulate and query collections of data, like slices/arrays and maps.
|
Package coll contains functions to help manipulate and query collections of data, like slices/arrays and maps. |
|
Package conv contains functions that help converting data between different types
|
Package conv contains functions that help converting data between different types |
|
Package data contains functions that parse and produce data structures in different formats.
|
Package data contains functions that parse and produce data structures in different formats. |
|
Package funcs is an internal package that provides gomplate namespaces and functions to be used in 'text/template' templates.
|
Package funcs is an internal package that provides gomplate namespaces and functions to be used in 'text/template' templates. |
|
Package genmonarch builds Monaco language definitions for the expression languages gomplate runs, from the grammars and registries gomplate itself uses -- so the editor cannot drift from the evaluator.
|
Package genmonarch builds Monaco language definitions for the expression languages gomplate runs, from the grammars and registries gomplate itself uses -- so the editor cannot drift from the evaluator. |
|
grammar
Package grammar extracts lexical vocabulary from the grammars of the parsers gomplate actually runs, so the editor tokenizers stay in step with them instead of being transcribed by hand.
|
Package grammar extracts lexical vocabulary from the grammars of the parsers gomplate actually runs, so the editor tokenizers stay in step with them instead of being transcribed by hand. |
|
hack
|
|
|
hostplayground
command
Command hostplayground stands in for a host like mission-control: it serves the playground API with a function of its own registered through playground.Options, so the whole path -- catalogue, highlighting, completion, hover, evaluation -- can be exercised the way a host will exercise it.
|
Command hostplayground stands in for a host like mission-control: it serves the playground API with a function of its own registered through playground.Options, so the whole path -- catalogue, highlighting, completion, hover, evaluation -- can be exercised the way a host will exercise it. |
|
internal
|
|
|
Package math contains set of basic math functions to be able to perform simple arithmetic operations
|
Package math contains set of basic math functions to be able to perform simple arithmetic operations |
|
Package playground evaluates expressions for the language playground, using the same entry points a gomplate caller uses so what the playground shows is what production does.
|
Package playground evaluates expressions for the language playground, using the same entry points a gomplate caller uses so what the playground shows is what production does. |
|
Package random contains functions for generating random values
|
Package random contains functions for generating random values |
|
Package regexp contains functions for dealing with regular expressions
|
Package regexp contains functions for dealing with regular expressions |
|
Package duration contains routines to parse standard units of time.
|
Package duration contains routines to parse standard units of time. |
|
Package test contains functions to help validate assumptions and can cause template generation to fail in specific cases
|
Package test contains functions to help validate assumptions and can cause template generation to fail in specific cases |
|
Package time contains functions to help work with date and time
|
Package time contains functions to help work with date and time |
|
Package tmpl contains functions for defining or executing in-line templates.
|
Package tmpl contains functions for defining or executing in-line templates. |