Data Types in GoLang

Explore the complete guide to GoLang data types including basic types (int, float, string), composite types (arrays, structs), reference types (slices, maps, channels), and interface types. Learn how each type works with practical examples and real-world usage scenarios.

Go lang is a statically typed language, meaning it checks for the datatypes during compilation. This will make final outcome predictable without any surprises. Like any other language, go offers simple set of data types out of the box which is more than sufficient

Basic types

Basic types are the simplest building blocks in Go, think of them as single values you can store directly, like a switch (bool), a number (int, float64, complex128), or text (string). You use them everywhere: counting items, storing IDs, calculating totals, comparing conditions, or holding a name. They don’t contain other types inside them (in the “collection” sense); they represent one piece of data at a time.

DataTypeWhat it storesRangeSize in memoryReal-world usage
booltrue/falsetrue, falseimplementation-dependent (often 1 byte; may pad in structs)flags, conditions, state checks
stringimmutable sequence of bytes (UTF-8 by convention)length: 0..(memory limit)header + data (implementation-dependent)names, JSON fields, HTTP payloads, logs
intsigned integer32-bit or 64-bit platform dependent4B or 8Bcounters, indexes, loop variables
int8signed 8-bit integer-128..1271Bbinary protocols, compact data
int16signed 16-bit integer-32768..327672Bprotocol fields, file formats
int32signed 32-bit integer-2147483648..21474836474Binterop, fixed-width numeric fields
int64signed 64-bit integer-9223372036854775808..92233720368547758078BIDs, timestamps, big counters
uintunsigned integerplatform dependent4B or 8Bsizes/counts that can’t be negative
uint8unsigned 8-bit integer0..2551Braw bytes, buffers
uint16unsigned 16-bit integer0..655352Bports, checksums
uint32unsigned 32-bit integer0..42949672954Bfixed-width protocol fields
uint64unsigned 64-bit integer0..184467440737095516158Bbitmasks, large counters
uintptrunsigned integer for pointer bit patternsplatform dependentpointer-sized (4B/8B)low-level/unsafe interop
bytealias for uint80..2551B[]byte for files/network
runealias for int32 (Unicode code point)-2147483648..2147483647 (Unicode commonly 0..0x10FFFF)4Bcharacter/text processing
float3232-bit floatapprox ±3.4e38 (finite)4Bsensor values, graphics
float6464-bit floatapprox ±1.8e308 (finite)8Bmetrics, scientific calc (not money)
complex64complex (2×float32)real/imag like float328BDSP, FFT
complex128complex (2×float64)real/imag like float6416BDSP/scientific with precision

Aggregate / Composite types

Aggregate/Composite types (arrays and structs) are “made of multiple values bundled together.” An array is a fixed-size list of the same type (like exactly 32 bytes for a hash), and a struct is a custom record that groups different fields under one name (like User{Name string, Age int}). You use these when you want to model real-world entities or keep related data together in a single unit.

DataTypeWhat it storesRangeSize in memoryReal-world usage
array ([N]T)fixed-length sequence of Tindex 0..N-1N * sizeof(T) (inline, self-contained)fixed buffers, hashes ([32]byte)
struct (struct{...})named fields grouped togetherN/Asum(fields) + padding/alignmentdomain models (User, Order), config structs

Reference types

Reference types (pointers, slices, maps, functions, channels) don’t primarily hold the data itself; instead, they refer to data or runtime-managed structures elsewhere. A slice points to an underlying array and can grow/shrink, a map refers to a hash table for fast key-based lookup, a channel refers to a concurrency queue used by goroutines, a function value can be passed around like data, and a pointer holds an address to another value. These are powerful because copying them is usually cheap (you’re copying the reference), while the actual data can be large and shared.

DataTypeWhat it storesRangeSize in memoryReal-world usage
pointer (*T)address of a T value (or nil)nil or points to Tpointer-sized (4B/8B)optional fields, avoid copying large structs
slice ([]T)dynamic view over arraylen/cap 0.. (memory limit)header (ptr,len,cap) + backing array elsewheremost common “list”, batches, JSON arrays
map (map[K]V)key-value hash tablegrows as neededheader + buckets (implementation-dependent)lookups, grouping, caching, counting
function (func(...) ...)callable function valuenil or callableimplementation-dependenthandlers, callbacks, middleware
channel (chan T)typed communication pipebuffered/unbufferedheader + runtime channel structureworker pools, pipelines, fan-in/fan-out

Interface types

Interface types describe behavior rather than a concrete shape: an interface says “any type that has these methods can be used here.” For example, io.Reader means “anything that can read bytes,” whether it’s a file, network connection, or in-memory buffer. Interfaces help you write flexible code, swap implementations easily, and test by mocking dependencies—without changing the code that uses them.

DataTypeWhat it storesRangeSize in memoryReal-world usage
interface (interface{...} / any)dynamic value + its type; method contractN/Aimplementation-dependentabstractions (io.Reader), dependency inversion, mocks

Conclusion

Understanding GoLang’s data type system is fundamental to writing efficient and maintainable code. From the simplicity of basic types to the power of interfaces and reference types, Go provides a well-thought-out type system that balances performance with ease of use. By mastering these data types, you’ll be well-equipped to build robust, scalable applications that leverage Go’s strengths in concurrency, memory management, and clean code design. Whether you’re working with APIs, building microservices, or developing system-level software, a solid grasp of GoLang data types will serve as the foundation for your success in Go programming.

srnyapathi
srnyapathi
Articles: 41