utils

package
v0.0.0-...-39b497c Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2021 License: MIT Imports: 22 Imported by: 64

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BashCmdExec

func BashCmdExec(cmd string, workingDir string, environ []string, logPrefix string) error

func CmdExec

func CmdExec(cmdName string, cmdArgs []string, workingDir string, environ []string, logPrefix string) error

func CopyDir

func CopyDir(src string, dst string) (err error)

CopyDir recursively copies a directory tree, attempting to preserve permissions. Source directory must exist, destination directory must *not* exist. Symlinks are ignored and skipped.

func CopyFile

func CopyFile(src, dst string) (err error)

CopyFile copies the contents of the file named src to the file named by dst. The file will be created if it does not already exist. If the destination file exists, all it's contents will be replaced by the contents of the source file. The file mode will be copied from the source and the copied data is synced/flushed to stable storage.

func ExpandPath

func ExpandPath(filePath string) (string, error)

func FileDelete

func FileDelete(filePath string) error

func FileExists

func FileExists(filePath string) bool

func FileWrite

func FileWrite(filePath string, content string, perm os.FileMode, dryRun bool) error

func GetEnv

func GetEnv(key string, defaultVal string) string

Simple helper function to read an environment or return a default value

func GetEnvAsBool

func GetEnvAsBool(name string, defaultVal bool) bool

Helper to read an environment variable into a bool or return default value

func GetEnvAsInt

func GetEnvAsInt(name string, defaultVal int) int

Simple helper function to read an environment variable into integer or return a default value

func GetEnvAsSlice

func GetEnvAsSlice(name string, defaultVal []string, sep string) []string

Helper to read an environment variable into a string slice or return default value

func LeftPad

func LeftPad(s string, padStr string, pLen int) string

func LeftPad2Len

func LeftPad2Len(s string, padStr string, overallLen int) string

func MapDeepCopy

func MapDeepCopy(m map[string]interface{}) (map[string]interface{}, error)

func MapKeys

func MapKeys(m map[string]interface{}) []string

func MapMerge

func MapMerge(maps ...map[string]string) map[string]string

func MapMergeGeneric

func MapMergeGeneric(maps ...map[string]interface{}) map[string]interface{}

func PopulatePathTemplate

func PopulatePathTemplate(pathTmplContent string, data interface{}) (string, error)

func PopulateTemplate

func PopulateTemplate(tmplContent string, data interface{}) (string, error)

func RightPad

func RightPad(s string, padStr string, pLen int) string

func RightPad2Len

func RightPad2Len(s string, padStr string, overallLen int) string

func SliceIncludes

func SliceIncludes(slice []string, item string) bool

func SnakeCaseToCamelCase

func SnakeCaseToCamelCase(inputUnderScoreStr string) (camelCase string)

func StdinQuery

func StdinQuery(question string) string

func StdinQueryBoolean

func StdinQueryBoolean(question string) bool

func StdinQueryInt

func StdinQueryInt(question string) (int, error)

func StdinQueryPassword

func StdinQueryPassword(question string) (string, error)

func StringToInt

func StringToInt(input string) (int, error)

func StringifyYAMLMapKeys

func StringifyYAMLMapKeys(in interface{}) interface{}

stringifyKeysMapValue recurses into in and changes all instances of map[interface{}]interface{} to map[string]interface{}. This is useful to work around the impedence mismatch between JSON and YAML unmarshaling that's described here: https://github.com/go-yaml/yaml/issues/139

Inspired by https://github.com/stripe/stripe-mock, MIT licensed

func StripIndent

func StripIndent(multilineStr string) string

func UniquePort

func UniquePort(data interface{}) (int, error)

https://play.golang.org/p/k8bws03uid

func UnsetEnv

func UnsetEnv(prefix string) (restore func())

UnsetEnv unsets all envars having prefix and returns a function that restores the env. Any newly added envars having prefix are also unset by restore. It is idiomatic to use with a defer.

defer UnsetEnv("ACME_")()

Note that modifying the env may have unpredictable results when tests are run with t.Parallel. NOTE: This is quick n' dirty from memory; write some tests for this code.

Types

This section is empty.

Jump to

Keyboard shortcuts

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