util

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2022 License: MPL-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoShellOnWindows = errors.New("shell{} is not supported on Windows. please use command{}")

ErrNoShellOnWindows occurs when GetShell() is run on a Windows machine.

View Source
var ErrUnknownShell = errors.New("unable to determine shell from environment. please set the $SHELL environment variable")

ErrUnknownShell occurs when the $SHELL environment variable is empty or not set.

Functions

func CopyDir

func CopyDir(to, src string, redactions []*redact.Redact) error

CopyDir copies a directory and all of its contents into a target directory.

func CopyFile

func CopyFile(to, src string, redactions []*redact.Redact) error

CopyFile copies a file to a target file path.

func EnsureDirectory added in v0.3.1

func EnsureDirectory(dir string) error

EnsureDirectory will ensure that the full path to the destination directory exists. If the full path exists, this is a no-op and will return nil. Otherwise, it will create any directories that do not exist in the destination path. Any directories created will be given file permissions 0755.

func FilterWalk

func FilterWalk(srcDir, filter string, since, until time.Time) ([]string, error)

FilterWalk accepts a source directory, filter string, and since and to Times to return a list of matching files.

func FindInInterface

func FindInInterface(iface interface{}, mapKeys ...string) (interface{}, error)

FindInInterface treats an interface{} like a (nested) map, and searches through its contents for a given list of mapKeys. For example, given an interface{} containing a map like iface ~ interface{}{"top": {"mid": {"bottom": "desired_value"}}} one could fetch an interface{} of "desired_value" with FindInInterface(iface, "top", "mid", "bottom") then afterwards cast it to a string, or whatever type you're expecting.

func GetShell

func GetShell() (string, error)

GetShell returns the value of the $SHELL environment variable, or an error if on Windows or the variable is not set.

func InterfaceToJSON

func InterfaceToJSON(mapVar interface{}) ([]byte, error)

InterfaceToJSON converts an interface{} to JSON.

func IsInRange

func IsInRange(target, since, until time.Time) bool

func JSONToFile

func JSONToFile(JSON []byte, outFile string) error

JSONToFile accepts JSON and an output file path to create a JSON file.

func SplitFilepath

func SplitFilepath(path string) (dir string, file string)

SplitFilepath takes a full path string and turns it into directory and file parts. In particular, it's useful for passing into runner.NewCopier()

func TarGz

func TarGz(sourceDir string, destFileName string, baseName string) error

TarGz is a utility function for archiving and compressing files. Its arguments include the source directory that you wish to archive; a destination filename, which is the .tar.gz file you want to create; and a baseName, which is the name of the directory that should be created when the resulting .tar.gz file is later extracted.

func WriteJSON

func WriteJSON(iface interface{}, filePath string) error

WriteJSON converts an interface{} to JSON then writes to filePath.

Types

This section is empty.

Jump to

Keyboard shortcuts

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