Now liveThe Skillselion MCP - thousands of ranked skills, loaded into your agent mid-task. No install.Get it →
cxuu avatar

Go Data Structures

  • 893 installs
  • 137 repo stars
  • Updated June 20, 2026
  • cxuu/golang-skills

go-data-structures is a Go agent skill that teaches slice pointer-length-capacity internals and backing-array aliasing so developers avoid memory and mutation bugs in dynamic Go data.

About

go-data-structures is a Go-focused agent skill from cxuu/golang-skills that distills Effective Go slice semantics into agent-actionable rules. The skill documents the three-item slice descriptor—pointer, length, and capacity—and shows how slices describe sections of underlying arrays rather than storing data independently. Developers reach for go-data-structures when agents generate or review Go code involving sub-slicing, append growth, shared backing storage, or nil slices, because subtle aliasing can cause cross-variable mutations and capacity surprises. Concrete examples cover creating slices from fixed arrays, interpreting len and cap after slicing, and recognizing when two slice variables observe the same memory. The skill is reference guidance for backend Go services, CLIs, and APIs where in-memory collection behavior affects correctness and performance reviews.

  • Explains the three-item slice descriptor: pointer, length, and capacity
  • Demonstrates how slices reference and mutate underlying arrays
  • Covers slice operator syntax including the three-index form for capacity control
  • Shows why append must return the slice due to pass-by-value header semantics
  • Includes concrete code examples from Effective Go for immediate application

Go Data Structures by the numbers

  • 893 all-time installs (skills.sh)
  • +39 installs in the week ending Aug 5, 2026 (Skillselion tracking)
  • Ranked #26 of 290 Python skills by installs in the Skillselion catalog
  • Security screen: LOW risk (skills.sh audit)
  • Data as of Aug 5, 2026 (Skillselion catalog sync)
npx skills add https://github.com/cxuu/golang-skills --skill go-data-structures

Add your badge

Show developers this skill is listed on Skillselion. Paste this into your README.

Listed on Skillselion
Installs893
repo stars137
Security audit3 / 3 scanners passed
Last updatedJune 20, 2026
Repositorycxuu/golang-skills

How do Go slice internals cause mutation bugs?

Master Go slice internals so their code avoids common memory and mutation bugs when working with dynamic data.

Who is it for?

Backend Go developers debugging unexpected slice mutations, capacity changes, or nil-slice behavior in services and CLIs.

Skip if: Developers who only need high-level Go syntax tutorials without runtime slice semantics or aliasing details.

When should I use this skill?

User asks about Go slices, len/cap, append growth, backing arrays, or mutation bugs across sub-slices

What you get

Agent guidance on slice descriptors, backing-array aliasing rules, and reviewed Go slice code patterns

  • Slice aliasing guidance
  • Reviewed Go slice code patterns

By the numbers

  • Documents the 3-part Go slice descriptor: pointer, length, and capacity

Files

SKILL.mdMarkdownGitHub ↗

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)

// Append a slice to a slice
x = append(x, y...)  // Note the ...

Two-Dimensional Slices

Independent inner slices (can grow/shrink independently):

picture := make([][]uint8, YSize)
for i := range picture {
    picture[i] = make([]uint8, XSize)
}

Single allocation (more efficient for fixed sizes):

picture := make([][]uint8, YSize)
pixels := make([]uint8, XSize*YSize)
for i := range picture {
    picture[i], pixels = pixels[:XSize], pixels[XSize:]
}

Declaring Empty Slices

Prefer nil slices over empty literals:

// Good: nil slice
var t []string

// Avoid: non-nil but zero-length
t := []string{}

Both have len and cap of zero, but the nil slice is the preferred style.

Exception for JSON: A nil slice encodes to null, while []string{} encodes to []. Use non-nil when you need a JSON array.

When designing interfaces, avoid distinguishing between nil and non-nil zero-length slices.

---

Maps

Implementing a Set

Use map[T]struct{} when the map is only a set. The empty struct takes no storage and makes membership intent explicit:

attended := map[string]struct{}{"Ann": {}, "Joe": {}}
if _, ok := attended[person]; ok {
    fmt.Println(person, "was at the meeting")
}

Use boolean map values only when the value carries a separate meaning beyond presence.

---

Copying

Be careful when copying a struct from another package. If the type has methods on its pointer type (*T), copying the value can cause aliasing bugs.

General rule: Do not copy a value of type T if its methods are associated with the pointer type *T. This applies to bytes.Buffer, sync.Mutex, sync.WaitGroup, and types containing them.

// Bad: copying a mutex
var mu sync.Mutex
mu2 := mu  // almost always a bug

// Good: pass by pointer
func increment(sc *SafeCounter) {
    sc.mu.Lock()
    sc.count++
    sc.mu.Unlock()
}

---

Quick Reference

TopicKey Point
SlicesAlways assign append result; nil slice preferred over []T{}
Setsmap[T]struct{} for membership-only sets
CopyingDon't copy T if methods are on *T; beware aliasing

Related Skills

  • Defensive copying: See go-defensive when copying slices or maps at API boundaries to prevent mutation
  • Capacity hints: See go-performance when pre-sizing slices or maps for known workloads
  • Iteration patterns: See go-control-flow when using range loops over slices, maps, or channels
  • Declaration style: See go-declarations when choosing between new, make, var, and composite literals

Related skills

How it compares

Choose this skill over generic Go style guides when the problem is runtime slice aliasing, not formatting or package layout.

FAQ

What is a Go slice descriptor?

go-data-structures defines a Go slice as a runtime descriptor with three parts: a pointer to the first element, length (len), and capacity (cap) to the end of the underlying array. Agents use this model to predict sharing and mutation across sub-slices.

Why do two Go slices mutate together?

go-data-structures explains that slices reference the same underlying array, so assigning through one sub-slice can change elements visible in another. The skill trains agents to flag shared backing storage during code review and refactoring.

Is Go Data Structures safe to install?

skills.sh reports 3 of 3 security scanners passed. Review the Security Audits panel on this page before installing in production.

Pythonbackend

This week in AI coding

Five minutes, every Monday - the tools, releases and tactics for developers.

unsubscribe anytime.