gomplate

package module
v3.24.7 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2024 License: MIT Imports: 28 Imported by: 15

README

Gomplate

Flanksource Gomplate is a fork of the https://github.com/hairyhenderson/gomplate tool and adds

  • A standard library interface for running templates using:
    • Go text/template
    • CEL (with celext, kubernetes extensions, and many gomplate functions remapped)
    • Javascript (otto)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateFuncs

func CreateFuncs(ctx context.Context) template.FuncMap

CreateFuncs - function mappings are created here

func GetCelEnv added in v3.20.19

func GetCelEnv(environment map[string]any) []cel.EnvOption

func LoadSharedLibrary added in v3.20.4

func LoadSharedLibrary(source string) error

LoadSharedLibrary loads a shared library for Otto

func RegisterType added in v3.20.24

func RegisterType(i any)

func RunExpression added in v3.20.19

func RunExpression(_environment map[string]any, template Template) (any, error)

func RunTemplate added in v3.20.4

func RunTemplate(environment map[string]any, template Template) (string, error)

func Serialize added in v3.20.19

func Serialize(in map[string]any) (map[string]any, error)

Serialize iterates over each key-value pair in the input map serializes any struct value to map[string]any.

Types

type Delims added in v3.20.23

type Delims struct {
	Left, Right string
}

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 {
	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:"-"`

	// 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:"-"`
}

func (Template) CacheKey added in v3.22.0

func (t Template) CacheKey(env map[string]any) string

func (Template) IsCacheable added in v3.24.0

func (t Template) IsCacheable() bool

func (Template) IsEmpty added in v3.20.4

func (t Template) IsEmpty() bool

Directories

Path Synopsis
Package base64 contains Base64 encoding/decoding functions
Package base64 contains Base64 encoding/decoding functions
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.
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 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.

Jump to

Keyboard shortcuts

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