Documentation ¶
Index ¶
- 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 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 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 FileExists ¶
FileExists checks if a file exists and is not a directory before we try using it to prevent further errors.
func FilterSplit ¶
FilterSplit removes all matching elements from a string slice based on a regexp selector and returns all the removed items too
func FilterStringMapByKey ¶
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 ¶
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 ¶
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 ¶
IsFileOrDir returns whether the passed path is an existing file or dir
func MapContains ¶
MapContains returns whether a map contains a certain element asValue denotes whether to check for values (if false will search for key)
func MergeStringMaps ¶
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 ¶
ReadJSONFile reads json from a file and stores it in the passed interface which should be a pointer
func ReadYAMLFile ¶
ReadYAMLFile reads yaml from a file and stores it in the passed interface which should be a pointer
func ReturnErrOnPanic ¶ added in v0.2.0
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 SelectMatching ¶
SelectMatching return all matching elements from a string slice based on a regexp selector
func Verify ¶
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 ¶
WriteJSONFile writes an object as json to the specified file path
func WriteYAMLFile ¶
WriteYAMLFile writes an object as yaml to the specified file path
Types ¶
type Validatable ¶
type Validatable interface {
IsValid() error
}
Validatable is a struct that can be checked for validity