Skip to content
Back to skills

Golang Data Structures

ASecurity

Choose and use Go data structures correctly: slices, maps, strings, arrays, containers, generics, pointers, and standard slices/maps helpers. Use when reasoning about aliasing, nil values, capacity, iteration, copying, or representation-sensitive performance.

  • 24 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added November 9, 2026
ai-agentsgoexpressawsapiperformance

Works with

  • cli
  • api

Security analysis

A100/100

Pro scans all 7 files and shows the line behind each finding

Scanned November 9, 2026

npx -y skills add aiproxer/aiproxer --skill golang-data-structures --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Golang Data Structures?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Golang Data Structures
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/aiproxer-golang-data-structures/badge)](https://www.skillsdirectory.com/skills/aiproxer-golang-data-structures)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: golang-data-structures
description: "Choose and use Go data structures correctly: slices, maps, strings, arrays, containers, generics, pointers, and standard slices/maps helpers. Use when reasoning about aliasing, nil values, capacity, iteration, copying, or representation-sensitive performance."
---

# Go data structures

Choose the representation from the contract and access pattern first. Measure memory and CPU behavior on the target workload before relying on layout or capacity assumptions.

## Focused review

For a review, keep the work read-only unless fixes are requested. Establish the review base, supported versions, and relevant contract; inspect changed code plus the callers and tests needed to assess it. Stay within this skill’s lens.

- Draw ownership through slicing, append, copy, Clone, Clip, Delete, map assignment, and returned values. Distinguish backing-storage independence from deep independence of elements.
- Check nil/empty wire shape and the equality function used, map iteration order, duplicate keys, NaN keys, and retention after shrinking a collection.
- Inspect range-variable copies, mutation while iterating, pointers to slice elements across growth, and callbacks that retain or mutate referenced values.
- For containers/generics, verify ordering and comparator laws, index maintenance, zero values, and complexity under the actual access pattern rather than implementation folklore.

Report each actionable finding with severity, confidence, file/symbol, trigger, consequence, and smallest remedy. Separate introduced/worsened defects from pre-existing debt, and state executed checks versus inference. If none survives validation, say so and identify coverage gaps.

## Slices

A slice is a descriptor over an array: pointer, length, and capacity. Slicing shares the backing array; `append` may reuse it or allocate a new one. Use `slices.Clone` to separate the outer backing array; it is shallow, so pointer/map/slice elements may still share mutable data. Use a full slice expression (`s[:len(s):len(s)]`) when append must allocate beyond the current length. Capacity clipping still aliases existing elements and retains the backing array; it provides neither deep isolation nor memory release.

Nil and empty slices differ for `reflect.DeepEqual` and JSON, while `slices.Equal` treats them as equal (`nil` commonly marshals as `null`, an allocated empty slice as `[]`). Preserve whichever meaning the API requires. `slices.Sort`, `SortFunc`, `BinarySearch`, `Clone`, `Compact`, `DeleteFunc`, `Grow`, and `Equal` are available in the standard library; check the module’s Go version before using newer helpers.

## Maps

Maps have reference-like behavior and are not safe for concurrent mutation. Nil maps can be read and ranged over but panic on assignment. Use a map for keyed lookup; use a typed map plus a mutex for ordinary shared state, `sync.Map` only when its documented workload fits.

Go’s current map implementation uses Swiss-table techniques (introduced in Go 1.24), but layout, bucket growth, and iteration order remain implementation details. Never write code or performance claims that depend on internal bucket fields. Map iteration order is deliberately unspecified; sort keys when output must be stable.

## Strings and bytes

Strings are immutable byte sequences, not guaranteed UTF-8. Use `[]byte` for mutable or I/O buffers and `[]rune` when indexing Unicode code points; use a Unicode-aware package when grapheme clusters or normalization matter. Conversions between strings and byte slices copy in ordinary Go code.

## Generics, arrays, and containers

Use generics when the operation is type-independent and a type parameter keeps the caller typed. Use an interface when behavior, not representation, is the abstraction. Arrays encode a fixed length; slices are the usual collection. `container/heap`, `container/list`, and `container/ring` are specialized—prefer slices and explicit indexes when they are clearer.

See [containers](references/containers.md), [generics](references/generics.md), [map representation](references/map-internals.md), [pointers](references/pointers.md), and [slice representation](references/slice-internals.md).

Files in this skill

  • SKILL.md4.1 KB
  • evals/evals.json20 KB
  • references/containers.md1.1 KB
  • references/generics.md982 B
  • references/map-internals.md1.1 KB
  • references/pointers.md1022 B
  • references/slice-internals.md1.2 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.