util

package
v0.1.3-test Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2022 License: MPL-2.0 Imports: 12 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) error

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

func CopyFile

func CopyFile(to, src string) error

CopyFile copies a file to a target file path.

func FilterWalk

func FilterWalk(srcDir, filter string, from, to time.Time) ([]string, error)

FilterWalk accepts a source directory, filter string, and from 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, from, to 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 seekers.NewCopier()

func TarGz

func TarGz(sourceDir string, destFileName string) error

TarGz accepts a source directory and destination file name to archive and compress files.

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