contact

package
v1.8.0 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package contact provides value objects related to contact information.

Package contact provides value objects related to contact information.

This package contains value objects that represent different types of contact information such as email addresses, phone numbers, and postal addresses. These value objects are immutable and follow the Value Object pattern from Domain-Driven Design.

Key value objects in this package:

  • Email: Represents an email address
  • Phone: Represents a phone number with formatting capabilities
  • Address: Represents a postal address

Each value object provides methods for:

  • Creating and validating instances
  • String representation
  • Equality comparison
  • Emptiness checking

The Phone value object additionally provides methods for:

  • Formatting in different standards (E.164, national, international)
  • Extracting country codes
  • Normalizing to standard formats
  • Validating for specific countries

Example usage:

// Create a new email address
email, err := contact.NewEmail("user@example.com")
if err != nil {
    // Handle validation error
}

// Create a new phone number
phone, err := contact.NewPhone("+1 (234) 567-8901")
if err != nil {
    // Handle validation error
}

// Format phone number in different ways
e164Format := phone.Format("e164")        // "+12345678901"
nationalFormat := phone.Format("national") // "(234) 567-8901"

// Create a new address
address, err := contact.NewAddress("123 Main St, Anytown, USA")
if err != nil {
    // Handle validation error
}

All value objects in this package are designed to be immutable, so they cannot be changed after creation. To modify a value object, create a new instance with the desired values.

Package contact provides value objects related to contact information.

Package contact provides value objects related to contact information.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Address

type Address string

Address represents a postal address value object

func NewAddress

func NewAddress(address string) (Address, error)

NewAddress creates a new Address with validation

func (Address) Equals

func (a Address) Equals(other Address) bool

Equals checks if two Addresses are equal

func (Address) IsEmpty

func (a Address) IsEmpty() bool

IsEmpty checks if the Address is empty

func (Address) String

func (a Address) String() string

String returns the string representation of the Address

func (Address) Validate

func (a Address) Validate() error

Validate checks if the Address is valid

type Email

type Email string

Email represents an email address value object

func NewEmail

func NewEmail(email string) (Email, error)

NewEmail creates a new Email with validation

func (Email) Equals

func (e Email) Equals(other Email) bool

Equals checks if two Emails are equal

func (Email) IsEmpty

func (e Email) IsEmpty() bool

IsEmpty checks if the Email is empty

func (Email) String

func (e Email) String() string

String returns the string representation of the Email

func (Email) Validate

func (e Email) Validate() error

Validate checks if the Email is valid

type Phone

type Phone string

Phone represents a phone number value object

func NewPhone

func NewPhone(phone string) (Phone, error)

NewPhone creates a new Phone with validation

func (Phone) CountryCode

func (p Phone) CountryCode() string

CountryCode returns the country code of the phone number

func (Phone) Equals

func (p Phone) Equals(other Phone) bool

Equals checks if two Phones are equal

func (Phone) Format

func (p Phone) Format(format string) string

Format formats the phone number according to the specified format Supported formats: - "e164": E.164 format (e.g., "+12345678901") - "national": National format (e.g., "(234) 567-8901") - "international": International format (e.g., "+1 234 567 8901") If an unsupported format is specified, the phone number is returned as is.

func (Phone) IsEmpty

func (p Phone) IsEmpty() bool

IsEmpty checks if the Phone is empty

func (Phone) IsValidForCountry

func (p Phone) IsValidForCountry(countryCode string) bool

IsValidForCountry checks if the phone number is valid for the specified country

func (Phone) Normalized

func (p Phone) Normalized() string

Normalized returns the phone number in E.164 format

func (Phone) String

func (p Phone) String() string

String returns the string representation of the Phone

func (Phone) Validate

func (p Phone) Validate() error

Validate checks if the Phone is valid

Jump to

Keyboard shortcuts

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