templates

package module
v0.5.4 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2022 License: MIT Imports: 21 Imported by: 2

README

Template Functions

Examples

Operating System Helpers
  • OS {{OS}} resolves to current running os runtime.GOOS
  • ARCH {{ARCH}} resolves to current processor architecture runtime.GOARCH
File and Path Functions
  • PWD {{PWD}} resolves to current working directory
  • FromSlash {{FromSlash}} uses go function filepath.FromSlash
  • ToSlash {{ToSlash}} uses go function filepath.ToSlash
  • ReadFile {{ReadFile}} read file contents, supports relative or absolute paths.
  • WriteFile {{WriteFile 'file/path' 'string data'}} write file contents, supports relative or absolute paths.
  • RemoveAll {{RemoveAll 'file/path'}} CAUTION removes file or folder and all children
  • MkdirAll {{MkdirAll}}
  • Touch {{Touch}}
String Functions
  • ToTitle {{ToTitle}} uses go function strings.Title
  • ToUpper {{ToUpper}} uses go function strings.ToUpper
  • ToLower {{ToLower}} uses go function strings.ToLower
  • Replace {{Replace}} uses go function strings.Replace
Execution Functions
EXEC
{{EXEC `echo "hello"`}}
TRY
{{TRY `fails` | default `default value`}}
Expand
{{Expand}}
ExpandFile
{{ReadFile `my-template-file.yaml` | ExpandFile | WriteFile}}
JQ
{{JQ 'key.value[0]', '{"key": {"value":[1]} }'}}
{{ReadFile `my-file.json` | JQ `key.value[0]`}}
YQ
{{ReadFile `my-file.yaml` | YQ `key.value[0]`}}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Expand added in v0.2.0

func Expand(str string, fn Functions) (string, error)

Expand Template String

func ExpandFile added in v0.2.0

func ExpandFile(file string, fn Functions) (string, error)

ExpandFile and return as a string

func GlobMatch added in v0.5.0

func GlobMatch(dir string, pattern string) ([]string, error)

GlobMatch

func Run

func Run(cmd CommandOptions) (val string, err error)

Run - run command

func SearchJSON added in v0.4.2

func SearchJSON(input string, search string) (data interface{}, err error)

SearchJSON a jmespath implementation for go

func SearchYAML added in v0.4.2

func SearchYAML(input string, search string) (data interface{}, err error)

SearchYAML converts yaml to JSON and runs a jmespath search

Types

type CommandOptions

type CommandOptions struct {
	Name       string
	Cmd        string
	Dir        string
	Env        []string
	UseStdOut  bool
	TrimOutput bool
}

CommandOptions - new command runner

type ExpandOptions added in v0.2.0

type ExpandOptions struct {
	Functions Functions
}

ExpandOptions to use when expanding a string.

type Functions

type Functions struct {
	Map template.FuncMap
}

Functions template function map

func (*Functions) Add added in v0.1.0

func (funcs *Functions) Add(key string, action interface{})

Add functions to the global template functions list.

func (*Functions) Init added in v0.2.5

func (funcs *Functions) Init() error

Init adds all default functions to the Map

type Variable added in v0.0.4

type Variable struct {
	Key         string
	Value       string
	OverrideEnv bool
}

Variable struct

type Variables added in v0.0.4

type Variables struct {
	List      []Variable
	Functions Functions
}

Variables struct

func (*Variables) Init added in v0.0.4

func (vars *Variables) Init() error

Init initialize new variables struct

func (*Variables) Resolve added in v0.0.4

func (vars *Variables) Resolve(v Variable) (val string, err error)

Resolve variable values

func (*Variables) Set added in v0.0.4

func (vars *Variables) Set(v Variable) error

Set both environment and variable values for use with template expansion

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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