Types

Classes for representing common data types

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:

Key Features

Comprehensive Type Coverage

Advanced Features

JSON Integration

Package Structure

Core Types

Collection Types

Temporal Types

Specialized Types

Utility Types

Usage Examples

Basic Type Usage

 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
// String type with constraints
stringType := &types.String{
MinLength: 1,
MaxLength: 100,
Pattern: "^[a-zA-Z0-9]+$",
}

// Integer type with range
intType := &types.Int{
Min: 0,
Max: 1000,
}

// Convert and validate values
value := stringType.From("hello")
if stringType.Sortable() {
// Handle sortable type
}

Collection Types

 1
2
3
4
5
6
7
8
9
10
// List of strings
listType := &types.List{
Val: &types.String{MaxLength: 50},
}

// Map with string keys and integer values
mapType := &types.Map{
K: &types.String{},
V: &types.Int{Min: 0},
}

Type Checking

1
2
3
4
5
6
7
8
if types.IsString(someType) {
// Handle string type
}

if types.IsList(someType) {
listType := types.TypeAs[*types.List](someType)
// Work with list type
}

Configuration

The types module supports various configuration options through individual type properties:

Source Code

See Also