Documentation
¶
Overview ¶
Package utils provides common utility functions for general purpose tasks. It includes helpers for URL validation, zero value checking, slice manipulation, map normalization, path handling, and deep copying objects.
Index ¶
- func DeepCopy[T any](src T) (dst T, err error)
- func DeepCopyWithMarshaling[T any](src T) (dst T, err error)
- func ExpandHome(path string) string
- func IsURL(str string) bool
- func IsZeroValue[S comparable](input S) bool
- func MergeMaps[T ~map[string]any](primary, secondary T) (T, error)
- func MergeMapsInPlace[T ~map[string]any](primary, secondary T) error
- func NormalizeMap(m map[string]any) map[string]any
- func PickByIndices[T any](s []T, indices []int) []T
- func SetIfZeroValue[S comparable](input *S, value S)
- func SetSliceIfNil[S ~[]T, T any](input *S, values ...T)
- func SetSliceIfZero[S ~[]T, T any](input *S, values ...T)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DeepCopyWithMarshaling ¶ added in v0.0.11
DeepCopyWithMarshaling creates a deep copy of a source object using JSON marshaling.
func ExpandHome ¶ added in v0.0.9
ExpandHome resolves home directory references in paths. Replaces leading ~ with the user's home directory path. Returns the original path if expansion fails or isn't needed.
func IsURL ¶
IsURL validates a string as a properly formatted URL. Returns true if the string contains both a scheme and host.
func IsZeroValue ¶ added in v0.0.1
func IsZeroValue[S comparable](input S) bool
IsZeroValue checks if a value equals its type's zero value. Works with any comparable type (numbers, strings, etc.).
func MergeMaps ¶ added in v0.0.11
MergeMaps constructs a merge between primary and secondary where primary values have priority.
func MergeMapsInPlace ¶ added in v0.0.11
MergeMaps constructs a merge between primary and secondary where primary values have priority. The primary map is modified in place.
func NormalizeMap ¶
NormalizeMap converts map keys to title case recursively. Creates a new map with all string keys converted to title case. Handles nested maps by recursively normalizing their keys as well.
func PickByIndices ¶ added in v0.0.11
func SetIfZeroValue ¶ added in v0.0.1
func SetIfZeroValue[S comparable](input *S, value S)
SetIfZeroValue conditionally updates a pointer's value. Sets the pointed-to value to a new value only if the current value equals the type's zero value.
func SetSliceIfNil ¶
func SetSliceIfNil[S ~[]T, T any](input *S, values ...T)
SetSliceIfNil initializes a nil slice pointer. Creates a new slice with the provided values only if the pointer is nil. Safe for any slice type.
func SetSliceIfZero ¶ added in v0.0.4
func SetSliceIfZero[S ~[]T, T any](input *S, values ...T)
SetSliceIfZero initializes an empty or nil slice pointer. Creates a new slice with the provided values if the current slice is nil or has zero length.
Types ¶
This section is empty.