Documentation
¶
Overview ¶
Package util provides generic helpers for common operations: empty checks, slice membership, deduplication, and phone formatting.
Role in architecture:
- Shared utilities: no business logic; pure functions used by handlers, use cases, or other packages.
Responsibilities:
- IsEmpty: reflect-based check for zero/nil/empty values (string, numeric, bool, ptr, slice, map).
- InAnySlice, RemoveDuplicates: generic slice helpers.
- FormatPhoneNumber: E.164 formatting via nyaruka/phonenumbers with optional default region.
This package must NOT:
- Depend on database, HTTP, or config; only standard library and phonenumbers.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FormatCurrency ¶ added in v0.3.5
FormatCurrency formats a numeric amount with the given currency code (e.g., "USD", "EUR", "GBP"). Returns a formatted currency string with the currency symbol and proper locale formatting. If formatting fails, returns a basic formatted string with currency code suffix.
func FormatPhoneNumber ¶ added in v0.1.16
FormatPhoneNumber parses phone with optional countryCode as default region and returns E.164-formatted string. Uses nyaruka/phonenumbers. If parsing or validation fails, returns the original phone unchanged.
func InAnySlice ¶
func InAnySlice[T comparable](haystack []T, needle T) bool
InAnySlice returns true if needle is equal to any element of haystack.
func IsEmpty ¶
func IsEmpty(value interface{}) bool
IsEmpty returns true if value is zero, nil, or empty (e.g. empty string, zero number, nil slice, empty map).
func RemoveDuplicates ¶
func RemoveDuplicates[T comparable](haystack []T) []T
RemoveDuplicates returns a new slice with duplicate elements removed; elements satisfying IsEmpty are omitted.
Types ¶
This section is empty.