helpers

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2026 License: MIT Imports: 15 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendStringUnique

func AppendStringUnique(slice []string, value string) []string

AppendStringUnique appends a string to a slice if it is not already in the slice

func AppendUnique

func AppendUnique(a, b []string) []string

AppendUnique appends all unique values from b to a

func ArgsReorg

func ArgsReorg(args ...string) []string

ArgsReorg reorganizes the arguments to be in the format of flags and non-flags

func AssertInteger

func AssertInteger(op string, value int, test int) bool

AssertInteger performs a comparison between an integer value and a test integer based on the provided operator. Supported operators: gt, lt, eq, ne, ge, le

func AssertString

func AssertString(op string, value string, test string) bool

AssertString performs a comparison between a string value and a test string based on the provided operator. Supported operators: eq, ne

func AssertSwitch

func AssertSwitch(value string, test map[string]interface{}) string

func CalculateMemoryUsage

func CalculateMemoryUsage(v interface{}, visited map[uintptr]bool) uintptr

CalculateMemoryUsage estimates the memory usage of an interface{} and all its nested elements

func CleanSlashes

func CleanSlashes(paths ...string) []string

CleanSlashes removes leading and trailing slashes from a string.

func CloneOf

func CloneOf(entity interface{}) (interface{}, bool)

CloneOf returns a deep copy of the given entity

func DebugAsPrettyJsonToBytes

func DebugAsPrettyJsonToBytes(lookupContext any) ([]byte, error, error)

DebugAsPrettyJsonToBytes returns the lookup context as a pretty json string

func DecodeToMap

func DecodeToMap(input interface{}) (map[string]interface{}, error)

DecodeToMap decodes an interface{} into a map[string]interface{}

func EscapeChars

func EscapeChars(s string, charsToEscape string, escapeChar string) string

EscapeChars Function to escape a set of characters in a string

func EscapeRedisValue

func EscapeRedisValue(query string) string

EscapeRedisValue Function to escape a string for use in a Redis query

func ExprToString

func ExprToString(expr ast.Expr) string

func FieldValue

func FieldValue(obj interface{}, field string) (interface{}, bool)

FieldValue returns the value of a field in a struct or map

func FindFileDown

func FindFileDown(dir, filename string) (string, error)

FindFileDown searches for a file in a directory and its subdirectories. It returns the path to the file if found, or an error if the file is not found.

func FindFileUp

func FindFileUp(filename string) (string, error)

FindFileUp searches for a file in the current directory and its parent directories. It returns the path to the file if found, or an error if the file is not found.

func FindStringIndex

func FindStringIndex(slice []string, target string) int

FindStringIndex Function to find the index of a string in a slice of strings Returns -1 if the string is not found

func Fprintf

func Fprintf(w *os.File, format string, args ...interface{}) (n int)

Fprintf writes to the given writer using the format specifier format, substituting any instances of %s or %v according to the format specifiers, writing to os.Stdout if no writer is provided.

func Fprintln

func Fprintln(w *os.File, format string) (n int)

Fprintln writes the text to the given writer, followed by a newline character, writing to os.Stdout if no writer is provided.

func FromMap

func FromMap(c interface{}, record map[string]interface{}) error

FromMap populates a struct from a map[string]interface{}

func GetFunctionOptions

func GetFunctionOptions(key string, defaultValue interface{}, options ...map[string]interface{}) (result interface{})

func GetModuleFromGoMod

func GetModuleFromGoMod() (string, error)

GetModuleFromGoMod returns the module name from the go.mod file.

func GetRootPathGoMod

func GetRootPathGoMod() (string, error)

GetRootPathGoMod returns the root path of the Go module.

func IsBytesIsInt

func IsBytesIsInt(value []byte) (intValue int, isInt bool)

IsBytesIsInt checks if a byte slice is a valid integer

func IsEmptyReflectValue

func IsEmptyReflectValue(v reflect.Value) bool

func IsEmptyValue

func IsEmptyValue(value any) bool

func IsNil

func IsNil(value interface{}) bool

func IsNumeric

func IsNumeric(i interface{}) bool

func IsPathExists

func IsPathExists(data map[string]interface{}, path []string) bool

IsPathExists checks if a nested path exists in a map[string]interface{}

func IsPointer

func IsPointer(v interface{}) bool

func IsSlice

func IsSlice(t interface{}) bool

IsSlice returns true if the given interface is a slice

func IsString

func IsString(i interface{}) bool

func IsStruct

func IsStruct(v any) bool

func Len

func Len(v interface{}) int

Len returns the length of a slice, array, map, or string

func MapKey

func MapKey(m *map[string]interface{}, key string) map[string]interface{}

MapKey creates a nested map if it doesn't exist, and returns the nested map.

func MapPtrKey

func MapPtrKey(m *map[string]interface{}, key string) *map[string]interface{}

MapPtrKey creates a nested map if it doesn't exist, and returns the nested map.

func MergeMaps

func MergeMaps(dst, src map[string]interface{}) map[string]interface{}

MergeMaps merges multiple maps into a single map.

func MergeMapsLevel0

func MergeMapsLevel0(maps ...map[string]interface{}) map[string]interface{}

MergeMapsLevel0 merges multiple maps into a single map without recursion.

func MergeObjectsToMap

func MergeObjectsToMap(exclude map[string]interface{}, objs ...interface{}) *map[string]interface{}

MergeObjectsToMap merges multiple objects into a single map, excluding keys specified in the exclude map.

func MustArray

func MustArray(i interface{}, byDefault ...[]interface{}) (arrayValue []interface{}, isType string)

func MustBool

func MustBool(i interface{}, byDefault ...bool) (boolValue bool, isType string)

func MustInt

func MustInt(i interface{}, byDefault ...int) (intValue int, isType string)

func MustString

func MustString(i interface{}, byDefault ...string) (stringValue string, isType string)

func NaturalLess

func NaturalLess(a, b string) bool

NaturalLess compares two strings in natural order.

func NowAsString

func NowAsString() string

NowAsString returns the current time as a string in RFC3339 format

func SanitizeServiceName

func SanitizeServiceName(input string) string

func SetFieldValue

func SetFieldValue(obj interface{}, field string, value any) (interface{}, bool)

SetFieldValue sets the value of a field in a struct or map

func SetFieldValueInt

func SetFieldValueInt(obj interface{}, field string, value int) (interface{}, bool)

SetFieldValueInt sets the value of a field in a struct or map

func SetFieldValueString

func SetFieldValueString(obj interface{}, field string, value string) (interface{}, bool)

SetFieldValueString sets the value of a field in a struct or map

func SplitString

func SplitString(item string, s string) (string, string)

func TimeToString

func TimeToString(t time.Time) string

TimeToString converts a time.Time to a string in RFC3339 format

func ToCamelCase

func ToCamelCase(input string) string

func ToMap

func ToMap(c interface{}) (map[string]interface{}, error)

ToMap converts a struct to a map[string]interface{}

func ToMapRecursive

func ToMapRecursive(c interface{}) (map[string]interface{}, error)

ToMapRecursive converts a struct to a map[string]interface{} recursively

func ToSnakeCase

func ToSnakeCase(input string) string

ToSnakeCase converts a string to snake_case

func TouchFile

func TouchFile(name string) error

TouchFile creates an empty file if it doesn't exist or updates the modification time if it does. It returns an error if the operation fails.

func UpdateMap

func UpdateMap(dst *map[string]interface{}, src map[string]interface{})

UpdateMap merges a map into another map. The first map is modified in place.

func UpdateMaps

func UpdateMaps(maps ...*map[string]interface{}) *map[string]interface{}

UpdateMaps merges multiple maps into a single map. The first map is modified in place and returned as a pointer. If the first map is nil, a new map is created.

Types

type NaturalSort

type NaturalSort []string

func (NaturalSort) Len

func (ns NaturalSort) Len() int

func (NaturalSort) Less

func (ns NaturalSort) Less(i, j int) bool

func (NaturalSort) Swap

func (ns NaturalSort) Swap(i, j int)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL