Golang (or Go) has a simple but powerful set of data types. Here's a quick breakdown of the main types you’ll encounter:
🔢 Basic Types
Type | Example | Description |
---|---|---|
int , int8 , int16 , int32 , int64 |
var a int = 42 |
Signed integers (size-specific) |
uint , uint8 , uint16 , uint32 , uint64 |
var b uint8 = 255 |
Unsigned integers |
float32 , float64 |
var c float64 = 3.14 |
Floating point numbers |
complex64 , complex128 |
var z complex128 = 1 + 2i |
Complex numbers |
byte |
alias for uint8 |
Used for raw data / binary |
rune |
alias for int32 |
Used for Unicode characters |
🧠Boolean
var isReady bool = true
🔤 String
var message string = "Hello, Go!"
📦 Aggregate Types
Type | Description |
---|---|
array |
Fixed-length sequence of elements |
slice |
Dynamic array |
map |
Key-value pairs (like a dictionary) |
struct |
Custom data structure |
Examples
arr := [3]int{1, 2, 3}
slice := []string{"Go", "Rust"}
m := map[string]int{"one": 1, "two": 2}
type User struct {
Name string
Age int
}
🧩 Pointer
var x = 10
var p *int = &x
🧱 Interface
type Shape interface {
Area() float64
}
🚀 Special types:
-
chan
: for channels (used in concurrency) -
func
: function type -
error
: standard error interface
Share this post
Related Posts
[Go Tutorials P1] Hello world
April 20, 2025
[Go Tutorials P3] Variable Declaration
April 21, 2025