template

package
v3.0.10 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2023 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package template serves to isolate the large number of public functions created by template_funcs.go. As this file is a copy of the version from confd, it is as unmodified as possible so as to allow for effective diffing when updates occur upstream. This package also exposes 2 of the private functions so they can be consumed by the clconf package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddFuncs

func AddFuncs(out, in map[string]interface{})

func Base64Decode

func Base64Decode(data string) (string, error)

func Base64Encode

func Base64Encode(data string) string

func CreateMap

func CreateMap(values ...interface{}) (map[string]interface{}, error)

CreateMap creates a key-value map of string -> interface{} The i'th is the key and the i+1 is the value

func EscapeOsgi

func EscapeOsgi(data string) string

func Fqdn

func Fqdn(hostname, domain string) string

Fqdn returns hostname if it contains a ., otherwise returns hostname.domain

func Getenv

func Getenv(key string, v ...string) string

Getenv retrieves the value of the environment variable named by the key. It returns the value, which will the default value if the variable is not present. If no default value was given - returns "".

func LookupIP

func LookupIP(data string) []string

func LookupIPV4

func LookupIPV4(data string) []string

func LookupIPV6

func LookupIPV6(data string) []string

func LookupSRV

func LookupSRV(service, proto, name string) []*net.SRV

func MarshalJSON added in v3.0.9

func MarshalJSON(data interface{}) (string, error)

MarshalJSON will return the JSON encoded representation of the supplied data.

func MarshalJSONString

func MarshalJSONString(data interface{}) (string, error)

MarshalJSONString will return the JSON encoded string representation of the supplied value. If data is not of type string, the fmt.Sprintf('%v', data) will be used prior to serialization to ensure a string type.

func MkdirAllNoUmask

func MkdirAllNoUmask(path string, perms os.FileMode) error

MkdirAllNoUmask is os.MkdirAll that ignores the current unix umask.

func NewFuncMap

func NewFuncMap(s *memkv.Store) map[string]interface{}

func RegexReplace

func RegexReplace(regex, src, repl string) (string, error)

RegexReplace maps to regexp.ReplaceAllString

func Reverse

func Reverse(values interface{}) interface{}

Reverse returns the array in reversed order works with []string and []KVPair

func Seq

func Seq(first, last int) []int

Seq creates a sequence of integers. It's named and used as GNU's seq. Seq takes the first and the last element as arguments. So Seq(3, 5) will generate [3,4,5]

func SortByLength

func SortByLength(values []string) []string

func SortByLengthKV

func SortByLengthKV(values []memkv.KVPair) []memkv.KVPair

func UnixModeToFileMode

func UnixModeToFileMode(unixMode string) (os.FileMode, error)

UnixModeToFileMode converts a unix file mode including special bits to a golang os.FileMode. The special bits (sticky, setuid, setgid) don't line up exactly between the two. Example: 02777 would set the setuid bit on unix but would end up 0777 if used as an os.FileMode

func UnmarshalJSONArray

func UnmarshalJSONArray(data string) ([]interface{}, error)

func UnmarshalJSONObject

func UnmarshalJSONObject(data string) (map[string]interface{}, error)

Types

type Template

type Template struct {
	// contains filtered or unexported fields
}

Template is a wrapper for template.Template to include custom template functions corresponding to confd functions.

func NewTemplate

func NewTemplate(name, text string, config *TemplateConfig) (*Template, error)

NewTemplate returns a parsed Template configured with standard functions.

func NewTemplateFromBase64

func NewTemplateFromBase64(name, template string, config *TemplateConfig) (*Template, error)

NewTemplateFromBase64 decodes base64 then calls NewTemplate with the result.

func NewTemplateFromFile

func NewTemplateFromFile(name, file string, config *TemplateConfig) (*Template, error)

NewTemplateFromFile reads file then calls NewTemplate with the result.

func (*Template) Execute

func (tmpl *Template) Execute(data interface{}) (string, error)

Execute will process the template text using data and the function map from confd.

type TemplateConfig

type TemplateConfig struct {
	Prefix      string
	SecretAgent *secret.SecretAgent
	LeftDelim   string
	RightDelim  string
}

TemplateConfig allows for optional configuration.

type TemplateOptions

type TemplateOptions struct {
	// CopyTemplatePerms uses the existing template permissions instead of FileMode for template
	// permissions
	CopyTemplatePerms bool
	// Flatten flattens the templates into the root of the dest instead of the preserving
	// the relative path under the source.
	Flatten bool
	// KeepEmpty forces empty result files to be written (usually not written or removed if already existing)
	KeepEmpty bool
	// KeepExistingPerms determines whether to use existing permissions on template files that are overwritten.
	KeepExistingPerms bool
	// Rm determines whether template files distinct from their target are deleted after processing.
	Rm bool
	// FileMode is the permissions to apply to template files when writing.
	FileMode os.FileMode
	// DirMode is the permission similar to FileMode but for new folders.
	DirMode os.FileMode
	// Extension is the extension to use when searching folders. If missing all files will be used.
	// The extension is stripped from the file name when templating.
	Extension string
	// LeftDelim is passed to go teplate.Delims
	LeftDelim string
	// RightDelim is passed to go teplate.Delims
	RightDelim string
}

TemplateOptions are settings for ProcessTemplates.

type TemplateResult

type TemplateResult struct {
	Src  string
	Dest string
}

TemplateResult stores the result of a single template processing.

func ProcessTemplates

func ProcessTemplates(srcs []string, dest string, value interface{}, secretAgent *secret.SecretAgent,
	options TemplateOptions,
) ([]TemplateResult, error)

ProcessTemplates processes templates. If dest is non empty it must be a folder into which templates will be placed after processing (the folder will be created if necessary). If empty templates are processed into the folders in which they are found.

Jump to

Keyboard shortcuts

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