util

package module
v1.4.3 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrParseID         = errors.New("failed to parse id").WithCode("ERR_PARSE_ID")
	ErrInvalidIDPrefix = func(prefix string) error {
		return errors.New("id must have prefix '%s_'", prefix).WithCode("ERR_INVALID_ID_PREFIX").WithKind(errors.KindInvalidInput)
	}
)

Functions

func CorrelationID added in v1.2.0

func CorrelationID(ctx context.Context) string

func Pick added in v1.3.0

func Pick[T any](items ...T) T

Pick randomly selects one item of the given list.

func RandomEmail added in v1.3.0

func RandomEmail() string

RandomEmail generate a random email.

func RandomPastTime added in v1.3.0

func RandomPastTime() time.Time

RandomPastTime generate a random past Time.

func RandomPhone added in v1.3.0

func RandomPhone() string

RandomPhone generate a random Brazilian phone.

func SafeValue

func SafeValue[T any](v *T) T

SafeValue returns the value associated to a pointer. If nil, returns the zero value of the given type.

func SortedKeys added in v1.2.0

func SortedKeys[K comparable, V any](m map[K]V) []K

func ToPointer

func ToPointer[T any](v T) *T

ToPointer returns a pointer reference to the given object.

func ToSnakeCase added in v1.2.0

func ToSnakeCase(str string) string

Types

type CanonicalID added in v1.4.0

type CanonicalID struct {
	// contains filtered or unexported fields
}

CanonicalID is a UUID v7 (time-ordered) with a type prefix. The prefix is API/log presentation only — storage must persist the raw 16-byte UUID.

func CanonicalIDFromUUID added in v1.4.0

func CanonicalIDFromUUID(prefix string, u uuid.UUID) CanonicalID

func MustParseCanonicalID added in v1.4.0

func MustParseCanonicalID(prefix, s string) CanonicalID

func NewCanonicalID added in v1.4.0

func NewCanonicalID(prefix string) CanonicalID

func ParseCanonicalID added in v1.4.0

func ParseCanonicalID(prefix, s string) (CanonicalID, error)

func (*CanonicalID) IsZero added in v1.4.0

func (id *CanonicalID) IsZero() bool

func (*CanonicalID) MarshalText added in v1.4.0

func (id *CanonicalID) MarshalText() ([]byte, error)

func (CanonicalID) String added in v1.4.0

func (id CanonicalID) String() string

func (CanonicalID) UUID added in v1.4.0

func (id CanonicalID) UUID() uuid.UUID

func (*CanonicalID) UnmarshalText added in v1.4.0

func (id *CanonicalID) UnmarshalText(b []byte) error

Jump to

Keyboard shortcuts

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