util

package
v0.16.2 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2018 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CanonicalPath added in v0.6.0

func CanonicalPath(path string, basePath string) (string, error)

Return the canonical version of the given path, relative to the given base path. That is, if the given path is a relative path, assume it is relative to the given base path. A canonical path is an absolute path with all relative components (e.g. "../") fully resolved, which makes it safe to compare paths as strings.

func CanonicalPaths added in v0.6.0

func CanonicalPaths(paths []string, basePath string) ([]string, error)

Return the canonical version of the given paths, relative to the given base path. That is, if a given path is a relative path, assume it is relative to the given base path. A canonical path is an absolute path with all relative components (e.g. "../") fully resolved, which makes it safe to compare paths as strings.

func CleanPath added in v0.9.0

func CleanPath(path string) string

Use this function when cleaning paths to ensure the returned path uses / as the path separator to improve cross-platform compatibility

func CloneStringList added in v0.13.19

func CloneStringList(listToClone []string) []string

Make a copy of the given list of strings

func CloneStringMap added in v0.13.19

func CloneStringMap(mapToClone map[string]string) map[string]string

Make a copy of the given map of strings

func CommaSeparatedStrings added in v0.12.17

func CommaSeparatedStrings(list []string) string

CommaSeparatedStrings returns an HCL compliant formatted list of strings (each string within double quote)

func CopyFile added in v0.9.4

func CopyFile(source string, destination string) error

Copy a file from source to destination

func CopyFolderContents added in v0.9.4

func CopyFolderContents(source string, destination string) error

Copy the files and folders within the source folder into the destination folder. Note that hidden files and folders (those starting with a dot) will be skipped.

func CreateLogger added in v0.6.0

func CreateLogger(prefix string) *log.Logger

Create a logger with the given prefix

func CreateLoggerWithWriter added in v0.13.3

func CreateLoggerWithWriter(writer io.Writer, prefix string) *log.Logger

CreateLoggerWithWriter Create a lgogger around the given output stream and prefix

func DeleteFiles added in v0.9.7

func DeleteFiles(files []string) error

Delete the given list of files. Note: this function ONLY deletes files and will return an error if you pass in a folder path.

func EncodeBase64Sha1 added in v0.9.7

func EncodeBase64Sha1(str string) string

Returns the base 64 encoded sha1 hash of the given string

func FileExists

func FileExists(path string) bool

Return true if the given file exists

func GetPathRelativeTo added in v0.4.0

func GetPathRelativeTo(path string, basePath string) (string, error)

Return the relative path you would have to take to get from basePath to path

func GetRandomTime added in v0.6.4

func GetRandomTime(lowerBound, upperBound time.Duration) time.Duration

Get a random time duration between the lower bound and upper bound. This is useful because some of our automated tests wound up flooding the AWS API all at once, leading to a "Subscriber limit exceeded" error. TODO: Some of the more exotic test cases fail, but it's not worth catching them given the intended use of this function.

func Grep

func Grep(regex *regexp.Regexp, glob string) (bool, error)

Returns true if the given regex can be found in any of the files matched by the given glob

func IsDir added in v0.13.5

func IsDir(path string) bool

Return true if the path points to a directory

func JoinPath added in v0.9.0

func JoinPath(elem ...string) string

Windows systems use \ as the path separator *nix uses / Use this function when joining paths to force the returned path to use / as the path separator This will improve cross-platform compatibility

func JoinTerraformModulePath added in v0.13.13

func JoinTerraformModulePath(modulesFolder string, path string) string

Join two paths together with a double-slash between them, as this is what Terraform uses to identify where a "repo" ends and a path within the repo begins. Note: The Terraform docs only mention two forward-slashes, so it's not clear if on Windows those should be two back-slashes? https://www.terraform.io/docs/modules/sources.html

func KindOf added in v0.12.9

func KindOf(value interface{}) reflect.Kind

Return the kind of the type or Invalid if value is nil

func ListContainsElement added in v0.6.0

func ListContainsElement(list []string, element string) bool

Return true if the given list contains the given element

func Min added in v0.14.1

func Min(x, y int) int

func PathContainsHiddenFileOrFolder added in v0.12.22

func PathContainsHiddenFileOrFolder(path string) bool

func ReadFileAsString added in v0.4.0

func ReadFileAsString(path string) (string, error)

Return the contents of the file at the given path as a string

func RemoveDuplicatesFromList added in v0.12.11

func RemoveDuplicatesFromList(list []string) []string

Returns a copy of the given list with all duplicates removed (keeping the first encountereds)

func RemoveDuplicatesFromListKeepLast added in v0.12.11

func RemoveDuplicatesFromListKeepLast(list []string) []string

Returns a copy of the given list with all duplicates removed (keeping the last encountereds)

func RemoveElementFromList added in v0.6.0

func RemoveElementFromList(list []string, element string) []string

Return a copy of the given list with all instances of the given element removed

func WriteFileWithSamePermissions added in v0.9.4

func WriteFileWithSamePermissions(source string, destination string, contents []byte) error

Write a file to the given destination with the given contents using the same permissions as the file at source

Types

This section is empty.

Jump to

Keyboard shortcuts

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