util

package
v0.5.5 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2026 License: MIT Imports: 6 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

func FormatCurrency(amount float64, currencyCode string) string

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

func FormatPhoneNumber(phone *string, countryCode *string) *string

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.

Jump to

Keyboard shortcuts

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