util

package
v0.1.15 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2018 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package util contains various utility methods for working with data (slice, map, nested map, string, time) as well as system-level primitives (files, exec).

Index

Constants

View Source
const (
	// ModeCompile just compiles all text templates on parameter tree without evaluating
	ModeCompile = iota

	// ModeEvaluate evaluates the whole parameter tree and all of its text templates, given a set of parameters
	ModeEvaluate = iota
)

Variables

This section is empty.

Functions

func ComparePasswords added in v0.1.6

func ComparePasswords(hashedPassword string, password string) bool

ComparePasswords verifies hashed password

func ContainsString

func ContainsString(a []string, v string) bool

ContainsString checks if a slice of strings contains a given string

func CopySliceOfStrings

func CopySliceOfStrings(a []string) []string

CopySliceOfStrings makes a copy of a given slice of strings

func CountElements

func CountElements(m interface{}) int

CountElements returns the number of elements in the structure, processing it recursively It adds up number elements in underlying maps and slices/arrays

func EscapeName

func EscapeName(str string) string

EscapeName escapes provided string by replacing # and _ with -

func FindYamlFiles added in v0.1.11

func FindYamlFiles(filePaths []string) ([]string, error)

FindYamlFiles returns all files found for given list of file paths that could be of the following types: * specific file path * directory (then all *.yaml files will be taken from it and all subdirectories) * file pattern like

func GetSortedStringKeys

func GetSortedStringKeys(m interface{}) []string

GetSortedStringKeys assumes m is a map[string]interface{} and returns an array of sorted keys

func HashAndSalt added in v0.1.6

func HashAndSalt(password string) string

HashAndSalt returns salted hash from the password (only used to generate user passwords)

func HashFnv

func HashFnv(s string) uint32

HashFnv calculates 32-bit fnv.New32a hash, given a string s

func ProcessIncludeMacros added in v0.1.11

func ProcessIncludeMacros(node NestedParameterMap, baseDir string) error

ProcessIncludeMacros walks through specified NestedParameterMap and resolves @include macros

func RandomID

func RandomID(rand *rand.Rand, length int) string

RandomID generates a random alphanumerical ID, which starts with a letter

func RunCmd

func RunCmd(cmdName string, cmdArgs ...string) (string, error)

RunCmd runs specified command with arguments and returns its standard output.

func StringContainsAny

func StringContainsAny(str string, substrings ...string) bool

StringContainsAny returns if string contains any of the given substrings

func WriteTempFile

func WriteTempFile(prefix string, data []byte) string

WriteTempFile creates a temporary file, writes given data into it and returns its name. It's up to a caller to delete the created temporary file by calling os.Remove() on its name.

Types

type NestedParameterMap

type NestedParameterMap map[string]interface{}

NestedParameterMap is a nested map of parameters, which allows to work with maps [string][string]...[string] -> string, int, bool values

func ProcessParameterTree

func ProcessParameterTree(tree NestedParameterMap, parameters *template.Parameters, cache *template.Cache, mode int) (NestedParameterMap, error)

ProcessParameterTree processes NestedParameterMap and calculates the whole tree, assuming values are text templates

func (NestedParameterMap) DeepEqual

func (src NestedParameterMap) DeepEqual(dst NestedParameterMap) bool

DeepEqual compares two nested parameter maps If both maps are empty (have zero elements), the method will return true

func (NestedParameterMap) Diff

Diff returns a human-readable diff between two nested parameter maps

func (NestedParameterMap) GetNestedMap

func (src NestedParameterMap) GetNestedMap(key string) NestedParameterMap

GetNestedMap returns nested parameter map by key

func (NestedParameterMap) GetString

func (src NestedParameterMap) GetString(key string, defaultValue string) (string, error)

GetString returns string located by provided key

func (NestedParameterMap) MakeCopy

func (src NestedParameterMap) MakeCopy() NestedParameterMap

MakeCopy makes a shallow copy of parameter structure

func (*NestedParameterMap) UnmarshalYAML

func (src *NestedParameterMap) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML is a custom unmarshal function for NestedParameterMap to deal with interface{} -> string conversions

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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