Technology
The types module provides a comprehensive type system for Project Forge applications. It offers a collection of structured data types with built-in validation, serialization, and type safety features.
Overview
This module provides a unified type system for representing and working with common data types in Go applications. It focuses on:
- Type Safety: Strongly typed representations with compile-time guarantees
- JSON Serialization: Built-in support for JSON marshaling and unmarshaling
- Validation: Configurable constraints and validation rules
- Extensibility: Composable type system with interfaces for custom types
Key Features
Comprehensive Type Coverage
- Primitive Types: String, Int, Float, Bool, Byte, Char
- Complex Types: List, Map, Set, OrderedMap, ValueMap
- Temporal Types: Date, Time, Timestamp, TimestampZoned
- Special Types: UUID, JSON, XML, Enum, Reference, Option
- Utility Types: Nil, Any, Unknown, Wrapped, Error
Advanced Features
- Type Conversion: Safe conversion between compatible types
- Default Values: Configurable default value generation
- Sorting Support: Built-in sortability indicators
- Scalar Detection: Distinction between scalar and composite types
- Range Constraints: Min/max validation for numeric and string types
JSON Integration
- Custom Marshaling: Optimized JSON serialization for all types
- Flexible Parsing: Intelligent type detection from JSON values
- Wrapped Types: Support for complex nested type structures
Package Structure
Core Types
type.go- Core type interface and utilitiesTypeinterface definition- Type casting and conversion utilities
- Common type checking functions
string.go- String type with length and pattern validationint.go- Integer type with range constraintsfloat.go- Floating-point type with precision controlsbool.go- Boolean type representation
Collection Types
list.go- Ordered collections with type constraintsmap.go- Key-value mappings with typed keys and valuesset.go- Unique value collectionsorderedmap.go- Ordered key-value mappingsvaluemap.go- Specialized value mappings
Temporal Types
date.go- Date-only representationstime.go- Time-only representationstimestamp.go- Combined date and timetimestampzoned.go- Timezone-aware timestamps
Specialized Types
uuid.go- UUID type with validationjson.go- Raw JSON value handlingxml.go- XML document representationenum.go- Enumeration type definitionsoption.go- Optional value handling
Utility Types
any.go- Dynamic type representationnil.go- Null value handlingunknown.go- Unknown type representationwrapped.go- Type composition and nestingreference.go- Reference type for complex relationships
Usage Examples
Basic Type Usage
1 | |
Collection Types
1 | |
Type Checking
1 | |
Configuration
The types module supports various configuration options through individual type properties:
- String constraints: MinLength, MaxLength, Pattern
- Numeric ranges: Min, Max values for Int and Float
- Collection settings: Value types for List, key/value types for Map
- Temporal formats: Custom formatting for date/time types
Source Code
- Repository: https://github.com/kyleu/projectforge/tree/main/module/types
- License: CC0 (Public Domain)
- Author: Kyle U (kyle@kyleu.com)
See Also
- Project Forge Documentation - Complete documentation