util

package
v0.1.12 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2018 License: Apache-2.0 Imports: 17 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) ToString

func (src NestedParameterMap) ToString() string

ToString returns a string representation of a nested parameter map

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

type TimeDiff

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

TimeDiff is wrapper for time.Duration with custom methods

func NewTimeDiff

func NewTimeDiff(duration time.Duration) *TimeDiff

NewTimeDiff wraps time.Duration into TimeDiff

func (*TimeDiff) Humanize

func (d *TimeDiff) Humanize() string

Humanize returns duration as short human-readable string

func (*TimeDiff) InDays

func (d *TimeDiff) InDays() int

InDays returns time duration in days

func (*TimeDiff) InHours

func (d *TimeDiff) InHours() int

InHours returns time duration in hours

func (*TimeDiff) InMinutes

func (d *TimeDiff) InMinutes() int

InMinutes returns time duration in minutes

func (*TimeDiff) InSeconds

func (d *TimeDiff) InSeconds() int

InSeconds returns time duration in seconds

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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