A data type specifies the values and operations permitted for data. Go combines primitive types with user-defined types to model domain concepts safely and expressively. section 5.0
Named types give reusable structure to related values. A person type can group a name and age, making declarations clearer than repeating an anonymous structure. section 3.6.1
Modeling people with a struct type
type person struct { name string; age int }; andy := person{name: "Andy", age: 42}; james := person{name: "James", age: 26}. Named struct values can then be accessed through fields such as andy.name and andy.age. section 3.6.1
Go’s type system supports domain modeling through structs, type aliases, interfaces, and composition. Compile-time checking catches invalid assignments early, while composition builds complex types from simpler ones rather than inheritance. section 5.0
Types also constrain collection and representation details:
- Treat an array’s length as part of its type: [4]int and [5]int are distinct and cannot be assigned to one another. section 4.1.2
- Use len() to obtain an array’s complete capacity, including positions that were not explicitly initialized. section 4.1.2
- Use pointers, type assertions, and type switches when managing references or checking concrete types at runtime. section 5.0
Listing 3.22 Using a type in a declaration
type person struct {
name string
age int
}
andy := person{
name: "Andy",
age: 42,
}
james := person{
name: "James",
age: 26,
}
fmt.Println(andy.name, andy.age) // output: Andy 42
fmt.Println(james.name, james.age) // output: James 26
Inspect the complete named-struct declaration and its concrete values. section 3.6.1

















