Documentation
¶
Index ¶
- func AnySliceToTypedSlice(input any) any
- func AppendSliceUnique[T comparable](slice1, slice2 []T) []T
- func ByteMapToStringMap(m map[string][]byte) map[string]string
- func Clean(str string) string
- func CombineErrors(errors ...error) error
- func CombineErrorsWithPrefix(prefix string, errorList ...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 IsOnlyNumeric(s string) bool
- func IsZero(i interface{}) bool
- func LimitPrintableRunes(s string, n int) string
- func LintName(name string) (should string)
- func PadRight(str string, length int, pad byte) string
- func ParseTime(input string) (time.Time, error)
- 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 StringSliceDiff(slice1, slice2 []string) []string
- func StringSliceDistinct(slice []string) []string
- func StringSliceEqualIgnoreOrder(a, b []string) bool
- func StringSliceHasDuplicates(slice []string) bool
- func StructToMap(s any) map[string]any
- func Tabify(str string, tab string) string
- func TabifyStringSlice(strs []string, tab string) []string
- func ToError(val interface{}) error
- 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 converts a slice of `any` (`[]interface{}`) into a strongly typed slice If mixed types are detected, it returns the original `[]any` to prevent panics.
func AppendSliceUnique ¶ added in v1.0.0
func AppendSliceUnique[T comparable](slice1, slice2 []T) []T
AppendSliceUnique appends elements from slice2 to slice1, ensuring uniqueness.
func ByteMapToStringMap ¶ added in v1.0.0
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 IsOnlyNumeric ¶ added in v1.1.0
IsOnlyNumeric returns true if the string only contains numeric characters
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 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 ParseTime ¶ added in v1.1.0
ParseTime parses a string into a time.Time object attempting to parse it as a variety of formats
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 values from the 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 returns 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 StringSliceDiff ¶
StringSliceDiff finds elements in slice1 that are not in slice2.
func StringSliceDistinct ¶ added in v0.3.0
func StringSliceEqualIgnoreOrder ¶ added in v0.9.0
func StringSliceHasDuplicates ¶ added in v0.3.0
StringSliceHasDuplicates returns whether a string slice has duplicate elements
func StructToMap ¶ added in v1.0.0
StructToMap uses reflection to convert a struct to a map
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 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.