Documentation
¶
Overview ¶
Package util provides generic utility functions for gokit applications.
It includes slice operations, pointer helpers, map utilities, string sanitization, and common validation helpers.
Index ¶
- func Coalesce[T comparable](values ...T) T
- func Contains[T comparable](slice []T, val T) bool
- func Deref[T any](p *T) T
- func Filter[T any](slice []T, predicate func(T) bool) []T
- func IsSafeString(s string) bool
- func Keys[K comparable, V any](m map[K]V) []K
- func Map[T any, U any](slice []T, transform func(T) U) []U
- func MaskSecret(s string, visiblePrefix int) string
- func ParseSize(s string, defaultBytes int64) int64
- func Ptr[T any](v T) *T
- func SanitizeEnvValue(s string) string
- func SanitizeString(s string) string
- func Unique[T comparable](slice []T) []T
- func ValidateNonEmpty(field, value string) error
- func ValidateUUID(field, value string) (uuid.UUID, error)
- func Values[K comparable, V any](m map[K]V) []V
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Coalesce ¶
func Coalesce[T comparable](values ...T) T
Coalesce returns the first non-zero value, or the zero value if all are zero.
func Contains ¶
func Contains[T comparable](slice []T, val T) bool
Contains checks if a slice contains a value.
func Deref ¶
func Deref[T any](p *T) T
Deref returns the value pointed to by p, or the zero value if p is nil.
func IsSafeString ¶
IsSafeString returns false if s contains patterns commonly associated with SQL injection or XSS attacks.
func MaskSecret ¶
MaskSecret hides sensitive parts of a string for safe display in logs. If the string is shorter than visiblePrefix, it is fully masked.
func ParseSize ¶
ParseSize parses a human-readable size string (e.g. "10MB", "512KB", "2GB") into bytes. Returns defaultBytes if the string cannot be parsed.
func SanitizeEnvValue ¶
SanitizeEnvValue cleans an environment variable value by removing surrounding quotes and trimming whitespace.
func SanitizeString ¶
SanitizeString trims whitespace and removes control characters from s.
func Unique ¶
func Unique[T comparable](slice []T) []T
Unique returns a slice with duplicate values removed, preserving order.
func ValidateNonEmpty ¶
ValidateNonEmpty validates that value is not empty after trimming whitespace.
func ValidateUUID ¶
ValidateUUID validates that value is a valid UUID string and returns the parsed UUID.
Types ¶
This section is empty.