2. Go's Types of Types

All types in Go fall into three broad categories:

Category
Description
Examples

Basic (built-in)

Predefined value types

string, int, float64, bool, complex128, byte, rune

Composite (constructed)

Built from other types

array, slice, map, struct, pointer, channel

Interface

Describes behavior (method sets)

interface{}, io.Reader, custom interfaces`

🧱 Basic Types (a.k.a. primitive types)

The simplest building blocks.

Type
Description
Example

bool

true or false

isReady := true

string

UTF-8 text

name := "Mario"

int

Integer (size depends on arch)

x := 42

int8, int16, int32, int64

Signed integers

age := int8(25)

uint8, uint16, ...`

Unsigned integers

count := uint8(255)

byte

Alias for uint8

'A' or bytes of a string

rune

Alias for int32 (Unicode code point)

'δΈ–'

float32, float64

Floating-point numbers

pi := 3.14159

complex64, complex128

Complex numbers

z := complex(2, 3)

🧠 These are value types β€” copies are made when you assign or pass them.

🧩 Composite Types (built from other types)

You use these to structure data.

Composite Type
Description
Example

Array

Fixed-length sequence of elements

var a [3]int = [3]int{1,2,3}

Slice

Dynamic list (backed by array)

s := []int{1,2,3}

Map

Key-value store (like Python dict)

m := map[string]int{"a":1,"b":2}

Struct

Group of named fields

type User struct {Name string; Age int}

Pointer

Memory address of a value

p := &x

Channel

Concurrency type for sending/receiving values

ch := make(chan int)

Function type

Functions as first-class values

var f func(int) int

🧩 Interface Types

Interfaces describe behavior, not structure.

  • Any type that defines a Read method with that exact signature implements Reader.

  • The empty interface interface{} means β€œany type” β€” because every type implements zero or more methods.

🧱 Type Declarations (custom types)

You can create your own named types based on any existing one.

These are distinct from their base types:

This enforces type safety, even though they share the same underlying representation.

🧩 Type Aliases

If you just want an alias (not a new type), use =:

type MyInt = int

βœ… MyInt and int are the exact same type β€” interchangeable.

🧠 The β€œType Hierarchy” Mental Model

🧩 Bonus: The interface{} β€œcatch-all” type

Go’s empty interface is the closest thing to Python’s object type β€” it can hold any value because every type implements zero methods.


🧠 TL;DR β€” The β€œTypes of Types” in Go

Category
Examples
Purpose

Basic Types

int, float64, bool, string

Simple values

Composite Types

array, slice, map, struct, pointer, chan, func

Combine or organize data

Interface Types

interface{}, custom interfaces

Define behavior

Custom Named Types

type Age int, type User struct {}

Domain-specific or safe wrappers

Type Aliases

type MyInt = int

Alternate name, not new type

Last updated