Skip to content

Commit 32a758c

Browse files
committed
ditto
1 parent 58de954 commit 32a758c

File tree

8 files changed

+409
-0
lines changed

8 files changed

+409
-0
lines changed

valueobject/appearance/doc.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Copyright (c) 2025 A Bit of Help, Inc.
2+
3+
// Package appearance provides value objects related to appearance information.
4+
//
5+
// This package contains value objects that represent visual appearance attributes
6+
// such as colors, styles, and other visual properties. These value objects are
7+
// immutable and follow the Value Object pattern from Domain-Driven Design.
8+
//
9+
// Key value objects in this package:
10+
// - Color: Represents a color in hexadecimal format (#RRGGBB)
11+
//
12+
// The Color value object provides methods for:
13+
// - Creating and validating colors in hexadecimal format
14+
// - Converting between different color formats
15+
// - Extracting RGB components
16+
// - Adding alpha channel information
17+
// - Determining if a color is dark or light
18+
// - Inverting colors
19+
//
20+
// Example usage:
21+
//
22+
// // Create a new color
23+
// color, err := appearance.NewColor("#FF5500")
24+
// if err != nil {
25+
// // Handle validation error
26+
// }
27+
//
28+
// // Get RGB components
29+
// r, g, b, err := color.RGB()
30+
// if err != nil {
31+
// // Handle error
32+
// }
33+
//
34+
// // Check if color is dark
35+
// isDark, err := color.IsDark()
36+
// if err != nil {
37+
// // Handle error
38+
// }
39+
//
40+
// // Invert the color
41+
// invertedColor, err := color.Invert()
42+
// if err != nil {
43+
// // Handle error
44+
// }
45+
//
46+
// All value objects in this package are designed to be immutable, so they cannot
47+
// be changed after creation. To modify a value object, create a new instance with
48+
// the desired values.
49+
package appearance

valueobject/cmd/generate/doc.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright (c) 2025 A Bit of Help, Inc.
2+
3+
// Package main provides a command-line tool for generating value objects.
4+
//
5+
// This tool automates the creation of value objects based on templates and
6+
// configuration files. It leverages the valueobject/generator package to
7+
// perform the actual generation of code.
8+
//
9+
// Usage:
10+
//
11+
// go run main.go [flags]
12+
//
13+
// The tool reads configuration from JSON files that specify the properties
14+
// and behavior of the value objects to be generated. It then creates Go files
15+
// with the appropriate code for these value objects, following the Value Object
16+
// pattern from Domain-Driven Design.
17+
//
18+
// This command-line tool is primarily used during development to:
19+
// - Generate new value object types quickly and consistently
20+
// - Ensure all value objects follow the same patterns and conventions
21+
// - Reduce boilerplate code when creating new value objects
22+
//
23+
// For more details on the configuration options and templates, see the
24+
// documentation in the valueobject/generator package.
25+
package main

valueobject/contact/doc.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// Copyright (c) 2025 A Bit of Help, Inc.
2+
3+
// Package contact provides value objects related to contact information.
4+
//
5+
// This package contains value objects that represent different types of contact
6+
// information such as email addresses, phone numbers, and postal addresses. These
7+
// value objects are immutable and follow the Value Object pattern from Domain-Driven
8+
// Design.
9+
//
10+
// Key value objects in this package:
11+
// - Email: Represents an email address
12+
// - Phone: Represents a phone number with formatting capabilities
13+
// - Address: Represents a postal address
14+
//
15+
// Each value object provides methods for:
16+
// - Creating and validating instances
17+
// - String representation
18+
// - Equality comparison
19+
// - Emptiness checking
20+
//
21+
// The Phone value object additionally provides methods for:
22+
// - Formatting in different standards (E.164, national, international)
23+
// - Extracting country codes
24+
// - Normalizing to standard formats
25+
// - Validating for specific countries
26+
//
27+
// Example usage:
28+
//
29+
// // Create a new email address
30+
// email, err := contact.NewEmail("[email protected]")
31+
// if err != nil {
32+
// // Handle validation error
33+
// }
34+
//
35+
// // Create a new phone number
36+
// phone, err := contact.NewPhone("+1 (234) 567-8901")
37+
// if err != nil {
38+
// // Handle validation error
39+
// }
40+
//
41+
// // Format phone number in different ways
42+
// e164Format := phone.Format("e164") // "+12345678901"
43+
// nationalFormat := phone.Format("national") // "(234) 567-8901"
44+
//
45+
// // Create a new address
46+
// address, err := contact.NewAddress("123 Main St, Anytown, USA")
47+
// if err != nil {
48+
// // Handle validation error
49+
// }
50+
//
51+
// All value objects in this package are designed to be immutable, so they cannot
52+
// be changed after creation. To modify a value object, create a new instance with
53+
// the desired values.
54+
package contact

valueobject/generator/doc.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// Copyright (c) 2025 A Bit of Help, Inc.
2+
3+
// Package generator provides code generation tools for value objects.
4+
//
5+
// This package contains utilities for generating value object code based on
6+
// templates and configuration files. It is designed to automate the creation
7+
// of value objects that follow the Value Object pattern from Domain-Driven Design.
8+
//
9+
// The package provides:
10+
// - A Generator type for generating value object code and tests
11+
// - Configuration types for specifying value object properties
12+
// - Command-line interface for using the generator from the terminal
13+
//
14+
// The generator supports two types of value objects:
15+
// - String-based value objects (wrapping a string type)
16+
// - Struct-based value objects (containing multiple fields)
17+
//
18+
// Configuration is provided through JSON files that specify:
19+
// - The name and package of the value object
20+
// - The type of value object (string or struct)
21+
// - Fields and their types (for struct-based value objects)
22+
// - Validation rules
23+
// - Required imports
24+
// - Description of the value object
25+
//
26+
// Example usage:
27+
//
28+
// // Create a generator
29+
// generator := generator.NewGenerator("templates", "output")
30+
//
31+
// // Configure a value object
32+
// config := generator.ValueObjectConfig{
33+
// Name: "Email",
34+
// Package: "contact",
35+
// Type: generator.StringBased,
36+
// BaseType: "string",
37+
// Description: "Represents an email address",
38+
// Validations: map[string]string{
39+
// "value": "ValidateEmail",
40+
// },
41+
// }
42+
//
43+
// // Generate the value object code
44+
// err := generator.Generate(config)
45+
// if err != nil {
46+
// // Handle error
47+
// }
48+
//
49+
// The package also provides a command-line interface through the Execute function,
50+
// which is used by the valueobject/cmd/generate package to provide a standalone
51+
// command-line tool.
52+
package generator

valueobject/identification/doc.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// Copyright (c) 2025 A Bit of Help, Inc.
2+
3+
// Package identification provides value objects related to identification.
4+
//
5+
// This package contains value objects that represent different types of identifiers
6+
// and identifying information such as IDs, names, usernames, and other personal
7+
// identifiers. These value objects are immutable and follow the Value Object pattern
8+
// from Domain-Driven Design.
9+
//
10+
// Key value objects in this package:
11+
// - ID: Represents a unique identifier (UUID)
12+
// - Name: Represents a person's name
13+
// - Username: Represents a username with validation rules
14+
// - DateOfBirth: Represents a person's date of birth
15+
// - DateOfDeath: Represents a person's date of death
16+
// - Gender: Represents a person's gender
17+
// - Password: Represents a password with security requirements
18+
//
19+
// Each value object provides methods for:
20+
// - Creating and validating instances
21+
// - String representation
22+
// - Equality comparison
23+
// - Emptiness checking
24+
//
25+
// Some value objects provide additional functionality specific to their domain:
26+
// - ID: Generation of new random UUIDs
27+
// - Username: Case conversion, length calculation, substring checking
28+
// - Password: Strength checking, hashing
29+
//
30+
// Example usage:
31+
//
32+
// // Create a new ID
33+
// id, err := identification.NewID("550e8400-e29b-41d4-a716-446655440000")
34+
// if err != nil {
35+
// // Handle validation error
36+
// }
37+
//
38+
// // Generate a random ID
39+
// randomID := identification.GenerateID()
40+
//
41+
// // Create a new name
42+
// name, err := identification.NewName("John Doe")
43+
// if err != nil {
44+
// // Handle validation error
45+
// }
46+
//
47+
// // Create a new username
48+
// username, err := identification.NewUsername("john_doe")
49+
// if err != nil {
50+
// // Handle validation error
51+
// }
52+
//
53+
// All value objects in this package are designed to be immutable, so they cannot
54+
// be changed after creation. To modify a value object, create a new instance with
55+
// the desired values.
56+
package identification

valueobject/location/doc.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Copyright (c) 2025 A Bit of Help, Inc.
2+
3+
// Package location provides value objects related to location information.
4+
//
5+
// This package contains value objects that represent geographical locations
6+
// and coordinates. These value objects are immutable and follow the Value Object
7+
// pattern from Domain-Driven Design.
8+
//
9+
// Key value objects in this package:
10+
// - Coordinate: Represents a geographic coordinate (latitude and longitude)
11+
//
12+
// The Coordinate value object provides methods for:
13+
// - Creating and validating coordinates
14+
// - Parsing coordinates from strings
15+
// - String representation and formatting in different formats (decimal, DMS, DM)
16+
// - Equality comparison
17+
// - Distance calculation between coordinates
18+
// - Directional comparison (north, south, east, west)
19+
// - JSON marshaling and conversion to maps
20+
//
21+
// Example usage:
22+
//
23+
// // Create a new coordinate
24+
// coord, err := location.NewCoordinate(37.7749, -122.4194)
25+
// if err != nil {
26+
// // Handle validation error
27+
// }
28+
//
29+
// // Parse a coordinate from a string
30+
// coord, err := location.ParseCoordinate("37.7749, -122.4194")
31+
// if err != nil {
32+
// // Handle parsing error
33+
// }
34+
//
35+
// // Calculate distance between coordinates
36+
// distance := coord.DistanceTo(otherCoord)
37+
//
38+
// // Format coordinate in different ways
39+
// decimalFormat := coord.Format("decimal") // "37.7749, -122.4194"
40+
// dmsFormat := coord.Format("dms") // "37° 46' 29.64" N, 122° 25' 9.84" W"
41+
//
42+
// All value objects in this package are designed to be immutable, so they cannot
43+
// be changed after creation. To modify a value object, create a new instance with
44+
// the desired values.
45+
package location

valueobject/measurement/doc.go

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// Copyright (c) 2025 A Bit of Help, Inc.
2+
3+
// Package measurement provides value objects related to measurement information.
4+
//
5+
// This package contains value objects that represent different types of measurements
6+
// such as monetary values, file sizes, memory sizes, percentages, ratings, and
7+
// temperatures. These value objects are immutable and follow the Value Object pattern
8+
// from Domain-Driven Design.
9+
//
10+
// Key value objects in this package:
11+
// - Money: Represents a monetary value with amount and currency
12+
// - FileSize: Represents a file size with different units (bytes, KB, MB, etc.)
13+
// - MemSize: Represents a memory size with different units (bytes, KB, MB, etc.)
14+
// - Percentage: Represents a percentage value
15+
// - Rating: Represents a rating value (e.g., 1-5 stars)
16+
// - Temperature: Represents a temperature value with different units
17+
//
18+
// Each value object provides methods for:
19+
// - Creating and validating instances
20+
// - String representation
21+
// - Equality comparison
22+
// - Conversion between different units or formats
23+
//
24+
// Many value objects also provide arithmetic operations appropriate to their domain:
25+
// - Money: Addition, subtraction, multiplication, division
26+
// - Percentage: Addition, subtraction, application to values
27+
// - Temperature: Conversion between units (Celsius, Fahrenheit, Kelvin)
28+
//
29+
// Example usage:
30+
//
31+
// // Create a new money value
32+
// amount := decimal.NewFromFloat(99.99)
33+
// money, err := measurement.NewMoney(amount, "USD")
34+
// if err != nil {
35+
// // Handle validation error
36+
// }
37+
//
38+
// // Perform arithmetic operations
39+
// tax, err := measurement.NewMoney(decimal.NewFromFloat(8.50), "USD")
40+
// if err != nil {
41+
// // Handle validation error
42+
// }
43+
// total, err := money.Add(tax)
44+
// if err != nil {
45+
// // Handle error (e.g., currency mismatch)
46+
// }
47+
//
48+
// // Create a percentage
49+
// discount, err := measurement.NewPercentage(15.0)
50+
// if err != nil {
51+
// // Handle validation error
52+
// }
53+
//
54+
// // Create a temperature
55+
// temp, err := measurement.NewTemperature(22.5, "C")
56+
// if err != nil {
57+
// // Handle validation error
58+
// }
59+
// fahrenheit := temp.ToFahrenheit()
60+
//
61+
// All value objects in this package are designed to be immutable, so they cannot
62+
// be changed after creation. To modify a value object, create a new instance with
63+
// the desired values.
64+
package measurement

0 commit comments

Comments
 (0)