This page explains the main categories of types in Go, their purpose, and when to use them.
Basic types are primitive data types provided by the Go language.
int
float64
bool
string
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)
Primitive /ˈprɪmɪtɪv/: basic built-in data type
UTF-8 /ˌjuːtiːɛf ˈeɪt/: variable-length text encoding
Alias types are alternative names for existing types.
byte (alias of uint8)
rune (alias of int32)
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
Alias /ˈeɪliəs/: another name for the same type
Unicode /ˈjuːnɪˌkoʊd/: universal character standard
Composite types are built from multiple values.
array
slice
map
struct
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
Composite /kəmˈpɒzɪt/: made from multiple parts
Dynamic /daɪˈnæmɪk/: size can change
Reference types store memory addresses instead of values.
pointer
Pointers allow functions to:
Modify values outside their scope
Avoid copying large data structures
Pointers use the * and & operators.
Pointer /ˈpɔɪntər/: variable holding a memory address
Memory address /ˈmɛməri əˈdrɛs/: location in memory
Behavior types define what an object can do, not what it is.
function
interface
Function: executable block of code
Interface: defines a set of method signatures
Interfaces are implemented implicitly in Go.
Behavior /bɪˈheɪvjər/: actions or capabilities
Implicit /ɪmˈplɪsɪt/: not explicitly declared
Concurrency types support parallel execution.
channel
Channels enable safe communication between goroutines.
They can be:
Unbuffered
Buffered
Channels help prevent race conditions.
Concurrency /kənˈkʌrənsi/: multiple tasks at the same time
Race condition /reɪs kənˈdɪʃən/: unsafe concurrent access
The error type is a built-in interface for error handling.
error
Errors represent failure states and are returned explicitly from functions.
Go encourages explicit error handling instead of exceptions.
Explicit /ɪkˈsplɪsɪt/: clearly stated
Exception /ɪkˈsɛpʃən/: error handling mechanism not used in Go
Category Purpose Basic Store simple values Alias Improve readability Composite Group data Reference Share memory Behavior Define actions Concurrency Enable parallelism Error Handle failures