identification

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package identification provides value objects related to identification.

Package identification provides value objects related to identification.

Package identification provides value objects related to identification.

This package contains value objects that represent different types of identifiers and identifying information such as IDs, names, usernames, and other personal identifiers. These value objects are immutable and follow the Value Object pattern from Domain-Driven Design.

Key value objects in this package:

  • ID: Represents a unique identifier (UUID)
  • Name: Represents a person's name
  • Username: Represents a username with validation rules
  • DateOfBirth: Represents a person's date of birth
  • DateOfDeath: Represents a person's date of death
  • Gender: Represents a person's gender
  • Password: Represents a password with security requirements

Each value object provides methods for:

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

Some value objects provide additional functionality specific to their domain:

  • ID: Generation of new random UUIDs
  • Username: Case conversion, length calculation, substring checking
  • Password: Strength checking, hashing

Example usage:

// Create a new ID
id, err := identification.NewID("550e8400-e29b-41d4-a716-446655440000")
if err != nil {
    // Handle validation error
}

// Generate a random ID
randomID := identification.GenerateID()

// Create a new name
name, err := identification.NewName("John Doe")
if err != nil {
    // Handle validation error
}

// Create a new username
username, err := identification.NewUsername("john_doe")
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 identification provides value objects related to identification.

Package identification provides value objects related to identification.

Package identification provides value objects related to identification.

Package identification provides value objects related to identification.

Package identification provides value objects related to identification.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DateOfBirth

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

DateOfBirth represents a date of birth value object

func NewDateOfBirth

func NewDateOfBirth(year, month, day int) (DateOfBirth, error)

NewDateOfBirth creates a new DateOfBirth with validation

func ParseDateOfBirth

func ParseDateOfBirth(dateStr string) (DateOfBirth, error)

ParseDateOfBirth creates a new DateOfBirth from a string in format "YYYY-MM-DD"

func (DateOfBirth) Age

func (dob DateOfBirth) Age() int

Age calculates the age based on the date of birth and current date

func (DateOfBirth) Date

func (dob DateOfBirth) Date() time.Time

Date returns the underlying time.Time value

func (DateOfBirth) Equals

func (dob DateOfBirth) Equals(other DateOfBirth) bool

Equals checks if two DateOfBirth values are equal

func (DateOfBirth) Format

func (dob DateOfBirth) Format(layout string) string

Format returns the date formatted according to the given layout

func (DateOfBirth) IsAdult

func (dob DateOfBirth) IsAdult() bool

IsAdult checks if the person is an adult (18 years or older)

func (DateOfBirth) IsEmpty

func (dob DateOfBirth) IsEmpty() bool

IsEmpty checks if the DateOfBirth is empty (zero value)

func (DateOfBirth) String

func (dob DateOfBirth) String() string

String returns the string representation of the DateOfBirth

type DateOfDeath

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

DateOfDeath represents a date of death value object

func NewDateOfDeath

func NewDateOfDeath(year, month, day int) (DateOfDeath, error)

NewDateOfDeath creates a new DateOfDeath with validation

func ParseDateOfDeath

func ParseDateOfDeath(dateStr string) (DateOfDeath, error)

ParseDateOfDeath creates a new DateOfDeath from a string in format "YYYY-MM-DD"

func (DateOfDeath) Date

func (dod DateOfDeath) Date() time.Time

Date returns the underlying time.Time value

func (DateOfDeath) Equals

func (dod DateOfDeath) Equals(other DateOfDeath) bool

Equals checks if two DateOfDeath values are equal

func (DateOfDeath) Format

func (dod DateOfDeath) Format(layout string) string

Format returns the date formatted according to the given layout

func (DateOfDeath) IsEmpty

func (dod DateOfDeath) IsEmpty() bool

IsEmpty checks if the DateOfDeath is empty (zero value)

func (DateOfDeath) IsRecent

func (dod DateOfDeath) IsRecent() bool

IsRecent checks if the death occurred within the last year

func (DateOfDeath) String

func (dod DateOfDeath) String() string

String returns the string representation of the DateOfDeath

func (DateOfDeath) TimeSinceDeath

func (dod DateOfDeath) TimeSinceDeath() int

TimeSinceDeath calculates the time elapsed since death in years

type Gender

type Gender string

Gender represents a person's gender value object

const (
	GenderMale   Gender = "male"
	GenderFemale Gender = "female"
	GenderOther  Gender = "other"
)

func NewGender

func NewGender(gender string) (Gender, error)

NewGender creates a new Gender with validation

func (Gender) Equals

func (g Gender) Equals(other Gender) bool

Equals checks if two Genders are equal

func (Gender) IsEmpty

func (g Gender) IsEmpty() bool

IsEmpty checks if the Gender is empty

func (Gender) String

func (g Gender) String() string

String returns the string representation of the Gender

type ID

type ID string

ID represents a unique identifier value object

func GenerateID

func GenerateID() ID

GenerateID creates a new random ID

func NewID

func NewID(id string) (ID, error)

NewID creates a new ID with validation

func (ID) Equals

func (id ID) Equals(other ID) bool

Equals checks if two IDs are equal

func (ID) IsEmpty

func (id ID) IsEmpty() bool

IsEmpty checks if the ID is empty

func (ID) String

func (id ID) String() string

String returns the string representation of the ID

type Name

type Name string

Name represents a person's name value object

func NewName

func NewName(name string) (Name, error)

NewName creates a new Name with validation

func (Name) Equals

func (n Name) Equals(other Name) bool

Equals checks if two Names are equal

func (Name) IsEmpty

func (n Name) IsEmpty() bool

IsEmpty checks if the Name is empty

func (Name) String

func (n Name) String() string

String returns the string representation of the Name

type Password

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

Password represents a password value object It stores the hashed password, not the plain text

func NewPassword

func NewPassword(plainPassword string) (Password, error)

NewPassword creates a new Password with validation and hashing

func (Password) Equals

func (p Password) Equals(other Password) bool

Equals checks if two Password values are equal This compares the underlying hashed passwords

func (Password) HashedPassword

func (p Password) HashedPassword() string

HashedPassword returns the base64-encoded hashed password

func (Password) IsEmpty

func (p Password) IsEmpty() bool

IsEmpty checks if the Password is empty

func (Password) Salt

func (p Password) Salt() []byte

Salt returns a copy of the salt used for hashing

func (Password) String

func (p Password) String() string

String returns a masked representation of the password Never returns the actual password or hash

func (Password) Verify

func (p Password) Verify(plainPassword string) bool

Verify checks if the provided plain password matches the stored hashed password

type Username

type Username string

Username represents a username value object

func NewUsername

func NewUsername(username string) (Username, error)

NewUsername creates a new Username with validation

func (Username) ContainsSubstring

func (u Username) ContainsSubstring(substring string) bool

ContainsSubstring checks if the username contains the given substring (case insensitive)

func (Username) Equals

func (u Username) Equals(other Username) bool

Equals checks if two Usernames are equal (case insensitive)

func (Username) IsEmpty

func (u Username) IsEmpty() bool

IsEmpty checks if the Username is empty

func (Username) Length

func (u Username) Length() int

Length returns the length of the username

func (Username) String

func (u Username) String() string

String returns the string representation of the Username

func (Username) ToLower

func (u Username) ToLower() Username

ToLower returns the lowercase version of the username

Jump to

Keyboard shortcuts

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