template

package
v2.17.1 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2024 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var FullStringEscapeFunction = escapeCharactersForJson

FullStringEscapeFunction fully escapes any special characters in the input string, ensure it is valid for use in JSON

View Source
var SimpleStringEscapeFunction = escapeSimpleCharacters

SimpleStringEscapeFunction only escapes newline characters in an input string

Functions

func EscapeSpecialCharacters

func EscapeSpecialCharacters(properties map[string]interface{}) (map[string]interface{}, error)

EscapeSpecialCharacters takes a map of config properties (some level of map (of maps...) of string) and escapes any newline characters in it Note: this is in use in both v1 config templating

func EscapeSpecialCharactersInValue

func EscapeSpecialCharactersInValue(value interface{}, escapeFunc StringEscapeFunction) (interface{}, error)

EscapeSpecialCharactersInValue takes a value and tries to escape any strings in it - it will walk recursively in case of maps/maps-of-maps of string and escape any special characters using a StringEscapeFunction. This is used by v1 config templating - with a simple function escaping newlines and v2 parameter values returns - with an escape function escaping strings to be fully JSON compliant

func UnmarshalYaml

func UnmarshalYaml(text string, fileName string) (map[string]map[string]string, error)

UnmarshalYaml takes the contents of a yaml file and converts it to a map[string]map[string]string. The file be templated, with any references replaced - or resulting in an error if no value is available.

The yaml file should have the following format:

some-name-1:

  • list-key-1: "list-entry-1"
  • list-key-2: "list-entry-2"

some-name-2:

  • list-key-1: "list-entry-1"

func UnmarshalYamlWithoutTemplating

func UnmarshalYamlWithoutTemplating(text string, fileName string) (map[string]map[string]string, error)

UnmarshalYamlWithoutTemplating takes the contents of a yaml file and converts it to a map[string]map[string]string. If references should be replaced (which you generally want) use UnmarshalYaml instead.

Types

type StringEscapeFunction

type StringEscapeFunction func(string) (string, error)

type Template

type Template interface {
	ExecuteTemplate(data map[string]string) (string, error)
}

Template wraps the underlying templating logic and provides a means of setting config values just on one place. It is intended to be language-agnostic, the file type does not matter (yaml, json, ...)

func NewTemplate

func NewTemplate(fs afero.Fs, fileName string) (Template, error)

NewTemplate creates a new template for the given file

func NewTemplateFromString

func NewTemplateFromString(name string, content string) (Template, error)

NewTemplateFromString creates a new template for the given string content

type UnmarshalYamlFunc

type UnmarshalYamlFunc func(text string, filename string) (map[string]map[string]string, error)

UnmarshalYamlFunc is a function that will Umarshal a yaml string of a config or environment definition into a map.

Jump to

Keyboard shortcuts

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