cxuu avatar

Go Data Structures

Go slice, map, and array idioms covering nil versus empty slices, append, sets, and copy safety.

CCM score
67 of 100
skills.sh installs
1.3K
GitHub stars
197
last updated
Aug 21, 2026
View on GitHub

Own this skill? Claim it

What it does

  • Covers slices, maps, and arrays: choosing new versus make, appending, declaring empty slices, and copying at boundaries
  • Includes a decision tree for picking arrays, slices, or maps, plus a references/SLICES.md file on nil versus empty slices and aliasing
  • Enforces nil slices by default, with non-nil empty slices only when JSON must encode [] rather than null
  • Designed for Go developers building or manipulating collections; concurrent access is handled by a separate concurrency skill

Install

$ npx -y skills add cxuu/golang-skills --skill go-data-structures -y

Installs into .agents/skills for every agent it finds here, and .claude/skills for Claude Code.

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)

Details

Repository
github.com/cxuu/golang-skills
Category
Go
First seen
May 16, 2026

More from cxuu/golang-skills

All 20

Similar to Go Data Structures

More Go