template

package
v0.9.4 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2023 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package template provides utility functions around reading and writing templates.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CopyData added in v0.9.2

func CopyData(src map[string]interface{}) (map[string]interface{}, error)

CopyData creates a deep copy of the argument map src.

func FlattenData

func FlattenData(src map[string]interface{}, fis []*FlattenInfo) (map[string]interface{}, error)

FlattenData returns the map of kes from src flattened into a single map.

func MergeData

func MergeData(dst map[string]interface{}, src map[string]interface{}) error

MergeData merges template data from src to dst. For all keys in flatten it will pop the key and merge back into dst.

func WriteBuffer

func WriteBuffer(text string, data map[string]interface{}) (*bytes.Buffer, error)

WriteBuffer creates a buffer with template `text` filled with values from `data`.

func WriteDir

func WriteDir(inputDir, outputDir string, data map[string]interface{}) error

WriteDir generates files to directory `outputDir` based on templates from directory `inputDir` and `data`.

func WriteFile

func WriteFile(in, out string, data map[string]interface{}) error

WriteFile generates `out` based on the `in` template and `data`.

Types

type FlattenInfo

type FlattenInfo struct {
	Key   string `hcl:"key,attr" json:"key"`
	Index *int   `hcl:"index,optional" json:"index,omitempty"`
}

FlattenInfo describes keys to flatten. If index is not a nil pointer then it is assumed the value is a list that must be flattened at the specific index.

Jump to

Keyboard shortcuts

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