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 ¶
- type Address
- type Email
- type Phone
- func (p Phone) CountryCode() string
- func (p Phone) Equals(other Phone) bool
- func (p Phone) Format(format string) string
- func (p Phone) IsEmpty() bool
- func (p Phone) IsValidForCountry(countryCode string) bool
- func (p Phone) Normalized() string
- func (p Phone) String() string
- func (p Phone) Validate() error
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 ¶
NewAddress creates a new Address with validation
type Email ¶
type Email string
Email represents an email address value object
type Phone ¶
type Phone string
Phone represents a phone number value object
func (Phone) CountryCode ¶
CountryCode returns the country code of the phone number
func (Phone) Format ¶
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) IsValidForCountry ¶
IsValidForCountry checks if the phone number is valid for the specified country
func (Phone) Normalized ¶
Normalized returns the phone number in E.164 format