Structs in Go

From the Go cheat sheet · Data Types & Structures · verified Jul 2026

Structs

Defining and using structs

go
// Define struct
type Person struct {
    Name string
    Age  int
}

// Create instance
p := Person{Name: "Alice", Age: 25}
p.Age = 26  // Access field
📦 Group related data with structs
🏷️ Tags for JSON/DB field mapping
🔄 Methods with value or pointer receivers
🎯 Composition over inheritance with embedding

More Go tasks

Back to the full Go cheat sheet