
Go Data Structures
Handles the practical decisions you run into when working with Go's core collections: when to use make versus a nil slice, why append needs assignment, how to implement sets with maps, and the aliasing traps with copying structs that have pointer receivers. The decision tree at the top is genuinely useful for picking between arrays, slices, and maps. Draws from Effective Go and the major style guides, so the advice is standard practice rather than opinion. Worth having open when you're writing collection manipulation code and want to avoid the common gotchas, especially around JSON marshaling of empty slices and the mutex copying footgun.
- skills.sh installs
- 1.3K
- GitHub stars
- 193
- last updated
- Aug 21, 2026
Install
$ npx -y skills add cxuu/golang-skills --skill go-data-structures --agent claude-codeInstalls into .claude/skills of the current project.
Files
Go Data Structures
Resource Routing
references/SLICES.md- Read when deciding nil versus empty slices, copying slices, or managing slice capacity and aliasing.
Choosing a Data Structure
What do you need?
├─ Ordered collection of items
│ ├─ Fixed size known at compile time → Array [N]T
│ └─ Dynamic size → Slice []T
│ ├─ Know approximate size? → make([]T, 0, capacity)
│ └─ Unknown size or nil-safe for JSON? → var s []T (nil)
├─ Key-value lookup
│ └─ Map map[K]V
│ ├─ Know approximate size? → make(map[K]V, capacity)
│ └─ Need a set? → map[T]struct{} (zero-size values)
└─ Need to pass to a function?
└─ Copy at the boundary if the caller might mutate it
When this skill does NOT apply: For concurrent access to data structures (mutexes, atomic operations), see go-concurrency. For defensive copying at API boundaries, see go-defensive. For pre-sizing capacity for performance, see go-performance.
Slices
The append Function
Always assign the result — the underlying array may change:
x := []int{1, 2, 3}
x = append(x, 4, 5, 6)
Sponsors
Details
- Repository
- github.com/cxuu/golang-skills
- Category
- Go
- First seen
- May 16, 2026
More from cxuu/golang-skills
All 20- Go Functional Options1.3K
- Go Control Flow1.3K
- Go Logging1.1K
- Go Functions1.1K
- Go Generics1.1K
- Go Declarations1.1K
- Go Code Review1.8K
- Go Testing1.4K
- Go Error Handling1.3K
- Go Linting1.3K
- Go Concurrency1.3K
- Go Interfaces1.3K
- Go Documentation1.3K
- Go Style Core1.3K
- Go Performance1.3K
- Go Context1.3K
- Go Naming1.3K
- Go Defensive1.3K
- Go Packages1.3K