Documentation ¶
Index ¶
- func AnySliceToTypedSlice(input any) any
- func Clean(str string) string
- func CloneStringMap(src map[string]string) map[string]string
- func CombineErrors(errors ...error) error
- func CombineErrorsWithPrefix(prefix string, errors ...error) error
- func DereferencePointer(val interface{}) interface{}
- func EscapePropertyName(name string) string
- func ExecuteMethod(item interface{}, methodName string) (returnValues []interface{}, err error)
- func FileHash(filePath string) (string, error)
- func FileMD5Hash(filePath string) ([]byte, error)
- func FilterMap[K comparable, V any](src map[K]V, keys []K) map[K]V
- func GetArrayValue(i interface{}, index int) (interface{}, bool)
- func GetCallingFunction(level int) string
- func GetFieldValueFromInterface(i interface{}, fieldName string) (interface{}, bool)
- func GetFunctionName(i interface{}) string
- func GetMD5Hash(text string) string
- func GetNestedFieldValueFromInterface(item interface{}, propertyPath string) (interface{}, bool)
- func InstantiateType(t reflect.Type) interface{}
- func IsFieldArray(fieldName string) (string, int, bool)
- func IsNil(i interface{}) bool
- func IsZero(i interface{}) bool
- func LimitPrintableRunes(s string, n int) string
- func LintName(name string) (should string)
- func MergeMaps[M ~map[K]V, K comparable, V any](old, new M) M
- func MergeStringMaps(a, b map[string]string) map[string]string
- func PadRight(str string, length int, pad byte) string
- func PrintableLength(str string) int
- func RemoveFromStringSlice(slice []string, values ...string) []string
- func Resize(s string, length uint) string
- func SliceToLookup[K comparable](src []K) map[K]struct{}
- func SortedMapKeys[V any](m map[string]V) []string
- func SplitByRune(str string, r rune) []string
- func SplitByWhitespace(str string) []string
- func StringFnvHash(s string) uint32
- func StringSliceContains(slice []string, val string) bool
- func StringSliceDiff(slice1, slice2 []string) (onlyInSlice1 []string)
- func StringSliceDistinct(slice []string) []string
- func StringSliceEqualIgnoreOrder(a, b []string) bool
- func StringSliceHasDuplicates(slice []string) bool
- func Tabify(str string, tab string) string
- func TabifyStringSlice(strs []string, tab string) []string
- func ToError(val interface{}) error
- func ToTypedSlice[T any](input []any) []T
- func TrimBlankLines(str string) string
- func TruncateString(str string, length int) string
- func UnescapePropertyName(name string) string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AnySliceToTypedSlice ¶ added in v0.9.0
AnySliceToTypedSlice determines whether input is []any and if so converts to an array of the underlying type
func CloneStringMap ¶
CloneStringMap :: clone a string map - return a copy of the map
func CombineErrors ¶ added in v0.3.0
func CombineErrorsWithPrefix ¶ added in v0.3.0
func DereferencePointer ¶
func DereferencePointer(val interface{}) interface{}
DereferencePointer checks if val is a pointer, and if so, dereferences it
func EscapePropertyName ¶ added in v0.4.0
EscapePropertyName replaces any '.' characters in the property name with propertyPathDotEscape
func ExecuteMethod ¶
ExecuteMethod use reflection to invoke method. We do not support functions which expect parameters.
func FileHash ¶ added in v0.5.0
FileHash streams a file into a MD5 hasher and returns the resultant MD5 hash as a HEX encoded string. Uses FileMD5Hash under-the-hood
func FileMD5Hash ¶ added in v0.5.0
FileMD5Hash streams a file into a MD5 hasher and returns the resultant MD5 hash bytes This DOES NOT read the whole file into memory
func FilterMap ¶ added in v0.8.0
func FilterMap[K comparable, V any](src map[K]V, keys []K) map[K]V
FilterMap builds a map based on `src`, but using only keys specified in `keys`
func GetArrayValue ¶
func GetCallingFunction ¶
GetCallingFunction :: return the calling function
level is how far up the call stack to go. so
func f1(){ f2() }
func f2(){ // returns "f2" helpers.GetCallingFunction(0) // returns "f1" helpers.GetCallingFunction(1) }
func GetFieldValueFromInterface ¶
GetFieldValueFromInterface uses reflection to return the value of the given property path
func GetFunctionName ¶
func GetFunctionName(i interface{}) string
GetFunctionName :: return the name of the given function
func GetMD5Hash ¶ added in v0.5.0
GetMD5Hash returns the MD5 hash of the given string
func GetNestedFieldValueFromInterface ¶
GetNestedFieldValueFromInterface uses reflection to return the value of the given nested property path
func InstantiateType ¶
InstantiateType returns a interface representing the zero value for the specified type.
func IsFieldArray ¶
TODO: add support for multi-dimensional arrays like - arr[1][2] arr[1][2][3] and so on..
func IsNil ¶ added in v0.3.0
func IsNil(i interface{}) bool
IsNil uses reflection to determine whether the given value is nil this is needed as a simple 'val == nil' check does not work for an interface https://mangatmodi.medium.com/go-check-nil-interface-the-right-way-d142776edef1
func IsZero ¶
func IsZero(i interface{}) bool
IsZero uses reflection to determine whether the given value is the zero value of it's type
func LimitPrintableRunes ¶ added in v0.3.0
LimitPrintableRunes limits the string to the given number of runes
func LintName ¶ added in v0.4.0
LintName modifies the given name to make common intialialisms upper case
func MergeMaps ¶ added in v0.6.0
func MergeMaps[M ~map[K]V, K comparable, V any](old, new M) M
MergeMaps merges 'new' onto 'old'. Values existing in old already have precedence Any value existing in new but not old is added to old returns a copy of the original map
func MergeStringMaps ¶
MergeStringMaps :: merge 2 string maps, returning a new map
func PadRight ¶ added in v0.5.0
PadRight returns a new string of a specified length in which the end of the current string is padded with spaces or with a specified Unicode character.
func PrintableLength ¶ added in v0.3.0
PrintableLength returns the number of printable runes in a string (after stripping ansi codes)
func RemoveFromStringSlice ¶
RemoveFromStringSlice removes the given string from the string slice
func Resize ¶ added in v0.5.0
Resize resizes the string with the given length. It ellipses with '…' when the string's length exceeds the desired length or pads spaces to the right of the string when length is smaller than desired
func SliceToLookup ¶ added in v0.6.0
func SliceToLookup[K comparable](src []K) map[K]struct{}
SliceToLookup converts a slice into a lookup
func SortedMapKeys ¶ added in v0.6.0
SortedMapKeys returnes the sorted keys of the map `m`
func SplitByRune ¶ added in v0.5.0
SplitByRune uses the CSV decoder to parse out the tokens - even if they are quoted and/or escaped
func SplitByWhitespace ¶ added in v0.5.0
SplitByWhitespace splits by the ' ' rune
func StringFnvHash ¶ added in v0.5.0
StringFnvHash returns a FNV1 hash of the given string. returns 0 if there's an error
func StringSliceContains ¶
StringSliceContains returns whether the string slice contains the given string
func StringSliceDiff ¶
StringSliceDiff returns values which only exists in the fist string slice
func StringSliceDistinct ¶ added in v0.3.0
StringSliceDistinct returns a slice with the unique elements the input string slice
func StringSliceEqualIgnoreOrder ¶ added in v0.9.0
func StringSliceHasDuplicates ¶ added in v0.3.0
StringSliceHasDuplicates returns whether a string slice has duplicate elements
func Tabify ¶ added in v0.2.0
Tabify adds the provided tab string to beginning of each line of string
func TabifyStringSlice ¶ added in v0.3.0
TabifyStringSlice adds the provided tab string to beginning of each line of string
func ToError ¶ added in v0.1.1
func ToError(val interface{}) error
ToError formats the supplied value as an error (or just returns it if already an error)
func ToTypedSlice ¶ added in v0.9.0
ToTypedSlice converts []any to []T
func TrimBlankLines ¶ added in v0.9.0
TrimBlankLines removes any empty lines from the string
func TruncateString ¶ added in v0.2.0
TruncateString limits the string to the given length, adding an ellipsis if the string is being truncated, also handles newlines
func UnescapePropertyName ¶ added in v0.4.0
UnescapePropertyName replaces any propertyPathDotEscape occurrences with "."
Types ¶
This section is empty.