Documentation ¶
Index ¶
- func DirExists(filename string) bool
- func Ensure(err error, message string)
- func FileExists(filename string) bool
- func Filter(selector *regexp.Regexp, slice []string) (out []string, numRemoved int)
- func FilterSplit(selector *regexp.Regexp, slice []string) (out, removed []string)
- func FilterStringMapByKey(selector *regexp.Regexp, m map[string]string) (filtered map[string]string)
- func FilterStringMapByValue(selector *regexp.Regexp, m map[string]string) (filtered map[string]string)
- func GetKeyByValue(m map[interface{}]interface{}, target interface{}) (interface{}, error)
- func IsFileOrDir(path string) bool
- func LogIfError(err error)
- func MapContains(m map[interface{}]interface{}, target interface{}, asValue bool) bool
- func MergeStringMaps(maps ...map[string]string) (out map[string]string, err error)
- func PanicIfErr(err error, customMessage string)
- func ReadJSONFile(filepath string, data interface{}) error
- func ReadYAMLFile(filepath string, data interface{}) error
- func ReturnErrOnPanic(perr *error) func()
- func ReturnFirstErr(errs ...error) error
- func RunCommand(cmd *exec.Cmd, path string, noOutput bool) string
- func SelectMatching(selector *regexp.Regexp, slice []string) (matching []string)
- func Verify(v Validatable, err error) error
- func WriteJSONFile(filepath string, data interface{}) error
- func WriteYAMLFile(filepath string, data interface{}) error
- type Parseable
- type Validatable
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Ensure ¶
Ensure checks for an error. If there is one it panics, if no error it prints the message (given it is not empty) `message` should describe what is ensured by the call and verification of `err` being `nil`
func FileExists ¶ added in v0.0.2
FileExists checks if a file exists and is not a directory before we try using it to prevent further errors.
func Filter ¶ added in v0.0.2
Filter removes all matching elements from a string slice based on a regexp selector
func FilterSplit ¶ added in v0.0.2
FilterSplit removes all matching elements from a string slice based on a regexp selector and returns all the removed items too
func FilterStringMapByKey ¶ added in v0.0.2
func FilterStringMapByKey(selector *regexp.Regexp, m map[string]string) (filtered map[string]string)
FilterStringMapByKey takes a map where a string is the key and filters it by matching the selector
func FilterStringMapByValue ¶ added in v0.0.2
func FilterStringMapByValue(selector *regexp.Regexp, m map[string]string) (filtered map[string]string)
FilterStringMapByValue takes a map where a string is the value and filters it by matching the selector
func GetKeyByValue ¶ added in v0.0.2
func GetKeyByValue(m map[interface{}]interface{}, target interface{}) (interface{}, error)
GetKeyByValue returns the key of a certain value of a map. It returns the first instance it finds that has the given value. It returns an err if the value is not in the map
func IsFileOrDir ¶ added in v0.0.2
IsFileOrDir returns whether the passed path is an existing file or dir
func LogIfError ¶
func LogIfError(err error)
LogIfError logs an error if it occurs, rather than repeating this structure everywhere
func MapContains ¶ added in v0.0.2
MapContains returns whether a map contains a certain element asValue denotes whether to check for values (if false will search for key)
func MergeStringMaps ¶ added in v0.0.2
MergeStringMaps merges the passed maps into a single map, errors on key clashes but still returns the merged map. Only final value of the clashed key remains
func PanicIfErr ¶
PanicIfErr panics in case of an error. If custom message it creates a new error based on that and returns that instead
func ReadJSONFile ¶ added in v0.0.2
ReadJSONFile reads json from a file and stores it in the passed interface which should be a pointer
func ReadYAMLFile ¶ added in v0.0.2
ReadYAMLFile reads yaml from a file and stores it in the passed interface which should be a pointer
func ReturnErrOnPanic ¶
func ReturnErrOnPanic(perr *error) func()
ReturnErrOnPanic catches panics, expects them to be of type error, then stores it in the pointer as recovery
func ReturnFirstErr ¶
ReturnFirstErr returns the first not-nil error from a list of errors. Used to prevent many copies of if err != nil { return err } when they are indepedent
func RunCommand ¶ added in v0.0.2
RunCommand runs an arbitrary os/exec.Cmd command as if you were in a terminal at the given path
func SelectMatching ¶ added in v0.0.2
SelectMatching return all matching elements from a string slice based on a regexp selector
func Verify ¶ added in v0.0.2
func Verify(v Validatable, err error) error
Verify calls IsValid on the parameter and saves the first error in case of an error it returns the error in the passed variable, it ensures no if err != nil repetition in code
func WriteJSONFile ¶ added in v0.0.2
WriteJSONFile writes an object as json to the specified file path
func WriteYAMLFile ¶ added in v0.0.2
WriteYAMLFile writes an object as yaml to the specified file path
Types ¶
type Validatable ¶ added in v0.0.2
type Validatable interface {
IsValid() error
}
Validatable is a struct that can be checked for validity