# Go data structures

> Go data structures is an open-source agent skill for developer tools. Guides Go code on slices, maps, sets and arrays to avoid aliasing and nil bugs. It is available on Claude Code, Codex, Cursor, Gemini CLI, GitHub Copilot, Windsurf and Goose.

- **Kind:** Skill
- **Pricing:** Open source
- **Platforms:** Claude Code, Codex, Cursor, Gemini CLI, GitHub Copilot, Windsurf, Goose
- **Website:** https://github.com/eduardo-sl/go-agent-skills/tree/main/skills/(code-quality)/go-data-structures
- **Repository:** https://github.com/eduardo-sl/go-agent-skills
- **GitHub stars:** 90
- **License:** MIT
- **Skill name:** go-data-structures
- **Collection:** https://github.com/eduardo-sl/go-agent-skills
- **Categories:** [developer tools](https://ai-powered.com/categories/developer-tools)
- **Listing updated:** 2026-12-02

## About

This skill gives the agent a set of rules for using Go's built-in collection types correctly. It covers the difference between nil and empty slices, when append can write into a shared backing array, how to copy or preallocate slices and maps, comma-ok lookups, writes to nil maps, and deterministic map iteration. It also includes guidance on choosing between slices, maps, sets and arrays, and on picking containers such as container/heap, container/list, sync.Map or a mutex-guarded map for specific jobs.

The agent works through a verification checklist covering nil handling, subslice retention, capacity, map shrinking and popping pointers from slices. A reference file, loaded on demand, adds examples for priority queues, LRU caches and weak-pointer caches. The skill asks the agent to read and edit Go files, run go and gofmt, and search the codebase.

It expects a Go project with the Go toolchain installed. Some advice depends on newer Go versions, such as slices.Sorted and maps.Keys from Go 1.23 and weak.Pointer from Go 1.24.

## When your agent uses it

> Correct use of Go's built-in data structures: slices (nil vs empty, append semantics, aliasing, preallocation), maps (comma-ok, sets, iteration order), arrays, and choosing between them. Use when: "slice vs array", "nil slice", "empty slice", "preallocate", "map iteration", "use a set in Go", "slice aliasing", "append gotcha", "copy a slice", "sync.Map or mutex". Not for: structures shared across goroutines (go-concurrency-review), allocation profiling (go-performance-review), generic containers (go-design-patterns).

## What it can access

From a static check of the files on GitHub; nothing was run.

- [Instructions only, no scripts](https://github.com/eduardo-sl/go-agent-skills/tree/HEAD/skills/(code-quality)/go-data-structures)
- [Asks for: Read, Edit, Write, Glob, Grep, Bash(go:*), Bash(gofmt:*)](https://github.com/eduardo-sl/go-agent-skills/blob/HEAD/skills/(code-quality)/go-data-structures/SKILL.md)
- [License: MIT](https://github.com/eduardo-sl/go-agent-skills/tree/HEAD/skills/(code-quality)/go-data-structures)

## Features

- **Nil vs empty slices:** Explains when a nil slice is preferable and where JSON output requires an empty slice.
- **Append and aliasing rules:** Shows when append can write into a caller's backing array and how to force a copy.
- **Preallocation guidance:** Recommends allocating slices and maps with known capacity and avoiding it when size is unknown.
- **Map safety and iteration:** Covers comma-ok lookups, nil map writes and sorting keys for deterministic output.
- **Set and container selection:** Provides a table mapping common needs to map, slice, heap, list or sync.Map choices.
- **Memory and copy behaviour:** Describes map shrinkage, slice clearing, pointer slot cleanup and shallow clone effects.

## Good for

- Review my Go code for slice aliasing bugs caused by append
- Remove duplicates from this list using a set in Go
- Make this function return an empty JSON array instead of null
- Preallocate the slices and maps in this Go loop
- Fix the panic from writing to a nil map
- Pick between sync.Map and a mutex-guarded map for this cache

## Install

### Any agent

Download the skill folder from https://github.com/eduardo-sl/go-agent-skills and copy it into your agent's skills folder.

## FAQ

### What does Go data structures need to run?

It requires the Go toolchain and is designed for Claude Code or similar AI coding agents working on Go projects.

### Does Go data structures run scripts or change files on its own?

It has no scripts. It lists allowed tools for reading, editing and writing files, searching, and running go and gofmt commands.

### When should I not use Go data structures?

The skill says not to use it for structures shared across goroutines, allocation profiling, or generic containers. Those are handled by other skills named in its description.

### Are there extra reference materials?

Yes. A reference file covers container/heap priority queues, LRU caches with container/list, reclaiming map memory, and a weak.Pointer cache, and is read only when needed.

### Does Go data structures run scripts?

No. It is instructions only, with no scripts. This comes from a static check of the files on GitHub; nothing was run. Read the files before you install it.

### Which AI agents can use Go data structures?

Claude Code, Codex, Cursor, Gemini CLI, GitHub Copilot, Windsurf and Goose. Each reads skills in the SKILL.md format from its own folder; the install steps on this page list them.

### What are the best alternatives to Go data structures?

The closest alternatives to Go data structures are Go defensive coding, Go interface design, Go coding standards, Go performance review and Go design patterns.

## Where this comes from

- Description: from the skill's own SKILL.md.

## Alternatives

- [Go defensive coding](https://ai-powered.com/skills/go-defensive-coding): Go defensive coding is an open-source agent skill for developer tools.
- [Go interface design](https://ai-powered.com/skills/go-interface-design): Go interface design is an open-source agent skill for developer tools.
- [Go coding standards](https://ai-powered.com/skills/go-coding-standards): Go coding standards is an open-source agent skill for developer tools.
- [Go performance review](https://ai-powered.com/skills/go-performance-review): Go performance review is an open-source agent skill for developer tools.
- [Go design patterns](https://ai-powered.com/skills/go-design-patterns): Go design patterns is an open-source agent skill for developer tools.
- [Go naming](https://ai-powered.com/skills/go-naming): Go naming is an open-source agent skill for developer tools.
- [Go documentation](https://ai-powered.com/skills/go-documentation): Go documentation is an open-source agent skill for developer tools.
- [Go test quality](https://ai-powered.com/skills/go-test-quality): Go test quality is an open-source agent skill for developer tools.

---
Source: https://ai-powered.com/skills/go-data-structures
