Table of Contents
Golang Type System Overview
This page explains the main categories of types in Go, their purpose, and when to use them.
1. Basic Types
Basic types are primitive data types provided by the Go language.
Examples
int
float64
bool
string
Explanation
Basic types store simple values such as numbers, booleans, and text.
int: stores whole numbers
float64: stores decimal numbers
bool: stores true or false
string: stores text (UTF-8 encoded)
Notes
Primitive /ˈprɪmɪtɪv/: basic built-in data type
UTF-8 /ˌjuːtiːɛf ˈeɪt/: variable-length text encoding
2. Alias Types
Alias types are alternative names for existing types.
Examples
byte (alias of uint8)
rune (alias of int32)
Explanation
Alias types do not create new types. They exist to improve code readability and express developer intent.
byte: used for raw or binary data
rune: used for Unicode characters
Notes
Alias /ˈeɪliəs/: another name for the same type
Unicode /ˈjuːnɪˌkoʊd/: universal character standard
3. Composite Types
Composite types are built from multiple values.
Examples
array
slice
map
struct
Explanation
Composite types allow grouping and organizing data.
Array: fixed-size collection of elements
Slice: dynamic view over an array
Map: key-value data structure
Struct: collection of named fields
Notes
Composite /kəmˈpɒzɪt/: made from multiple parts
Dynamic /daɪˈnæmɪk/: size can change
4. Reference Types
Reference types store memory addresses instead of values.
Examples
pointer
Explanation
Pointers allow functions to:
Modify values outside their scope
Avoid copying large data structures
Pointers use the * and & operators.
Notes
Pointer /ˈpɔɪntər/: variable holding a memory address
Memory address /ˈmɛməri əˈdrɛs/: location in memory
5. Behavior Types
Behavior types define what an object can do, not what it is.
Examples
function
interface
Explanation
Function: executable block of code
Interface: defines a set of method signatures
Interfaces are implemented implicitly in Go.
Notes
Behavior /bɪˈheɪvjər/: actions or capabilities
Implicit /ɪmˈplɪsɪt/: not explicitly declared
6. Concurrency Types
Concurrency types support parallel execution.
Examples
channel
Explanation
Channels enable safe communication between goroutines.
They can be:
Unbuffered
Buffered
Channels help prevent race conditions.
Notes
Concurrency /kənˈkʌrənsi/: multiple tasks at the same time
Race condition /reɪs kənˈdɪʃən/: unsafe concurrent access
7. Error Type
The error type is a built-in interface for error handling.
Examples
error
Explanation
Errors represent failure states and are returned explicitly from functions.
Go encourages explicit error handling instead of exceptions.
Notes
Explicit /ɪkˈsplɪsɪt/: clearly stated
Exception /ɪkˈsɛpʃən/: error handling mechanism not used in Go
Summary
Category Purpose Basic Store simple values Alias Improve readability Composite Group data Reference Share memory Behavior Define actions Concurrency Enable parallelism Error Handle failures
