golang-data-structures
Skill3.4k starsChanged 2 months agoMITView on GitHub
Golang data structures — slices (internals, capacity growth, preallocation, slices package), maps (internals, hash buckets, maps package), arrays, container/list/heap/ring, strings.Builder vs bytes.Buffer, generic collections, pointers (unsafe.Pointer, weak.Pointer), and copy semantics. Use when choosing or optimizing Go data structures, implementing generic containers, using container/ packages, unsafe or weak pointers, or questioning slice/map internals. Not for applying optimization patterns once profiling has identified a bottleneck (→ See `samber/cc-skills-golang@golang-performance` skill).
- Installs packages
4 other projects use a version of this, 3 of them edited.
Trending
Quiet since October.about the whole repository
Most recently taken up by
- rzisso/golang-skillsword for word, first seen Sep 16, 2026
- gccli/skillsedited, first seen Jul 27, 2026
- alexastrum/skledited, first seen Jun 12, 2026
- guynhsichngeodiec/cc-skills-golangedited, first seen Apr 7, 2026
Who's talking about samber/cc-skills-golang
- @golangch.bsky.social“A collection of Golang agentic skills that works #golang github.com/samber/cc-s...”Bluesky · Jul 16, 2026 · 10 likes
- @samber.bsky.social“My Go skill set: github.com/samber/cc-skills-golang npx skills add samber/cc-skills-golang Open to …”Bluesky · Mar 23, 2026 · 6 likes
- LobsterTrap/lola“[FEATURE] - Cherry Pick Skills”GitHub · May 6, 2026 · 3 reactions
- @golangch.bsky.social“Claude Code Skills for production-ready Golang projects #golang github.com/samber/cc-s...”Bluesky · Mar 29, 2026 · 3 likes
- A Hacker News story“A collection of 35 Golang Agent Skills”Hacker News · Mar 23, 2026 · 3 points
The biggest 5 of 45 mentions linking to the repository that our crawl found. Each line is their own headline.
See all 45
Talked about on GitHub, Bluesky and Hacker News (45 times).
On GitHub · 41
- May 6, 2026[FEATURE] - Cherry Pick Skills — LobsterTrap/lola3 reactions · 1 comment
- Jul 16, 2026Skills with nested metadata maps are silently dropped during discovery — charmbracelet/crush1 reaction
- Mar 30, 2026[SUBMISSION] cc-skills-golang — ProSkillsMD/proskills1 reaction · 1 comment
- Oct 4, 2026claude-code-plugins.github.samber.cc-skills-golang: init at 2.0.0 — sudosubin/agents.nix0 reactions
- Oct 1, 2026agent-skills.github.samber.cc-skills-golang: init at 2.0.0 — sudosubin/agents.nix0 reactions
36 more on GitHub
- Sep 23, 2026Update skill: /samber-golang-structs-interfaces (safe risk) — aiskillstore/marketplace0 reactions
- Sep 23, 2026Update skill: /samber-golang-spf13-viper (safe risk) — aiskillstore/marketplace0 reactions
- Sep 23, 2026Update skill: /samber-golang-benchmark (medium risk) — aiskillstore/marketplacesays it tested it0 reactions
- Sep 23, 2026Update skill: /samber-golang-pkg-go-dev (high risk) — aiskillstore/marketplace0 reactions
- Sep 23, 2026Update skill: /samber-golang-samber-ro (safe risk) — aiskillstore/marketplace0 reactions
- Sep 23, 2026Update skill: /samber-golang-uber-fx (safe risk) — aiskillstore/marketplace0 reactions
- Sep 23, 2026Update skill: /samber-golang-stretchr-testify (safe risk) — aiskillstore/marketplace0 reactions
- Sep 23, 2026Update skill: /samber-golang-swagger (safe risk) — aiskillstore/marketplace0 reactions
- Sep 23, 2026Update skill: /samber-golang-stay-updated (safe risk) — aiskillstore/marketplace0 reactions
- Sep 6, 2026Update skill: /samber-golang-spf13-cobra (safe risk) — aiskillstore/marketplace0 reactions
- Sep 6, 2026Update skill: /samber-golang-cli (safe risk) — aiskillstore/marketplace0 reactions
- Sep 6, 2026Update skill: /samber-golang-lint (medium risk) — aiskillstore/marketplace0 reactions
- Sep 6, 2026Update skill: /samber-golang-samber-slog (medium risk) — aiskillstore/marketplace0 reactions
- Sep 6, 2026Update skill: /samber-golang-modernize (safe risk) — aiskillstore/marketplace0 reactions
- Sep 6, 2026Update skill: /samber-golang-samber-lo (safe risk) — aiskillstore/marketplace0 reactions
- Sep 6, 2026Update skill: /samber-golang-documentation (safe risk) — aiskillstore/marketplace0 reactions
- Sep 5, 2026corpus tier3 cites an id with no path: the largest source's provenance handle cannot be followed — jonhill90/agent-estate0 reactions · 1 comment
- Sep 3, 2026chore: sync upstream skills (auto) — marcioaltoe/skills0 reactions
- Sep 2, 2026chore: sync upstream skills (auto) — marcioaltoe/skills0 reactions
- Aug 19, 2026add `samber` golang skills — greenbone/opensight-golang-libraries0 reactions · 4 comments
- Jul 17, 2026fix: import skills with nested metadata and surface parse errors — gridctl/gridctl0 reactions
- Jul 17, 2026fix: skill import fails on nested metadata frontmatter with misleading 'no SKILL.md files found' error — gridctl/gridctl0 reactions
- Jul 16, 2026chore: sync upstream skills — marcioaltoe/skills0 reactions
- Jul 3, 2026New skill: /samber-golang-performance (safe risk) — aiskillstore/marketplace0 reactions
- Jul 1, 2026New skill: /samber-golang-error-handling (low risk) — aiskillstore/marketplace0 reactions
- Jul 1, 2026New skill: /samber-golang-code-style (low risk) — aiskillstore/marketplace0 reactions
- Jun 26, 2026Integrate samber/cc-skills-golang: install full general-purpose set + full-list reminder at plan & each scenario — ArcadeAI/safeword0 reactions · 3 comments
- Jun 26, 2026[FEATURE] Add Golang skills selectively — inference-gateway/cli0 reactions
- Jun 24, 2026chore(skills): sync upstream skills — marcioaltoe/skills0 reactions
- Jun 7, 2026feature/naming-linting-testing-skills — joekhosbayar/go-mightysays it tested it0 reactions
- May 22, 2026🔐 ci: pin + sandbox the skills install in claude-review.yml — martinciu/ccpulse0 reactions
- May 21, 2026🔐 ci: pin or sandbox the unpinned npx skills install in claude-review.yml — martinciu/ccpulse0 reactions · 1 comment
- Apr 25, 2026Audit candidate: samber/cc-skills-golang — xiaolai/nlpm0 reactions · 3 comments
- Mar 30, 2026[Resource]: cc-skills-golang — hesreallyhim/awesome-claude-code0 reactions · 1 comment
- Mar 29, 2026golang skills — sushichan044/dotfiles0 reactions
- Mar 22, 2026Add a claude code skills for Golang — jqueryscript/awesome-claude-code0 reactions
On Bluesky · 3
- Jul 16, 2026A collection of Golang agentic skills that works #golang github.com/samber/cc-s... — @golangch.bsky.social10 likes and reposts
- Mar 23, 2026My Go skill set: github.com/samber/cc-skills-golang npx skills add samber/cc-skills-golang Open to contributions. If you're building skills… — @samber.bsky.social6 likes and reposts
- Mar 29, 2026Claude Code Skills for production-ready Golang projects #golang github.com/samber/cc-s... — @golangch.bsky.social3 likes and reposts · 1 reply
On Hacker News · 1
- Mar 23, 2026A collection of 35 Golang Agent Skills3 points · 2 comments
Other versions4 projects use a version of this.
Word for word · 1
- rzisso/golang-skills★ 0100% same
Edited · 3
- alexastrum/skl★ 1097% same
- gccli/skills★ 097% same
- guynhsichngeodiec/cc-skills-golang★ 097% same
Wrote their own version · 0
None found.
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository46 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- golang-benchmarkSkill
- golang-cliSkill
- golang-code-styleSkill
- golang-concurrencySkill
- golang-contextSkill
- golang-continuous-integrationSkill
- golang-databaseSkill
- golang-dependency-injectionSkill
- golang-dependency-managementSkill
- golang-design-patternsSkill
- golang-documentationSkill
- golang-error-handlingSkill
- golang-google-wireSkill
- golang-goplsSkill
- golang-graphqlSkill
- golang-grpcSkill
- golang-how-toSkill
- golang-lintSkill
- golang-modernizeSkill
- golang-namingSkill
- golang-observabilitySkill
- golang-performanceSkill
- golang-pkg-go-devSkill
- golang-popular-librariesSkill
- golang-project-layoutSkill
- golang-refactoringSkill
- golang-safetySkill
- golang-samber-doSkill
- golang-samber-hotSkill
- golang-samber-loSkill
- golang-samber-moSkill
- golang-samber-oopsSkill
- golang-samber-roSkill
- golang-samber-slogSkill
- golang-securitySkill
- golang-spf13-cobraSkill
- golang-spf13-viperSkill
- golang-stay-updatedSkill
- golang-stretchr-testifySkill
- golang-structs-interfacesSkill
- golang-swaggerSkill
- golang-testingSkill
- golang-troubleshootingSkill
- golang-uber-digSkill
- golang-uber-fxSkill
The file
We split this skill into the rules it gives an agent
7 rules. 3 are common, 0 are distinctive, and 4 are very specific to this project.
3
Common
Most of the 3 edited versions we read keep these.
0
Distinctive
This author's own choices. Worth a look.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Common: line 35
Arrays: SHOULD be preferred over slices only for fixed, compile-time-known sizes (hash digests, IPv4 addresses, matrix dimensions)
- Very specific: line 38
strings.Builder: MUST be preferred for building strings. - Very specific: line 40
unsafe.Pointer: MUST only follow the 6 valid conversion patterns from the Go spec — NEVER store in a uintptr variable across statements - Common: line 105
Prefer slices for everything else — arrays cannot grow and pass by value (expensive for large sizes).
- Very specific: line 120
Use strings.Builder for pure string concatenation (avoids copy on String()), bytes.Buffer when you need io.Reader or byte manipulation.
- Very specific: line 124
Use the tightest constraint possible.
- Common: line 165
When using third-party libraries, refer to their official documentation and code examples for current API signatures.
“Common” is measured: kept by at least 6 in 10 of the 3 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Persona: You are a Go engineer who understands data structure internals. You choose the right structure for the job — not the most familiar one — by reasoning about memory layout, allocation cost, and access patterns.
Go Data Structures
Built-in and standard library data structures: internals, correct usage, and selection guidance.
- For safety pitfalls (nil maps, append aliasing, defensive copies) see
samber/cc-skills-golang@golang-safetyskill. - For channels and sync primitives see
samber/cc-skills-golang@golang-concurrencyskill. - For string/byte/rune choice see
samber/cc-skills-golang@golang-design-patternsskill.
Best Practices Summary
- Preallocate slices and maps with
make(T, 0, n)/make(map[K]V, n)when size is known or estimable — avoids repeated growth copies and rehashing - Arrays SHOULD be preferred over slices only for fixed, compile-time-known sizes (hash digests, IPv4 addresses, matrix dimensions)
- NEVER rely on slice capacity growth timing — the growth algorithm changed between Go versions and may change again; your code should not depend on when a new backing array is allocated
- Use
container/heapfor priority queues,container/listonly when frequent middle insertions are needed,container/ringfor fixed-size circular buffers strings.BuilderMUST be preferred for building strings;bytes.BufferMUST be preferred for bidirectional I/O (implements bothio.Readerandio.Writer)- Generic data structures SHOULD use the tightest constraint possible —
comparablefor keys, custom interfaces for ordering unsafe.PointerMUST only follow the 6 valid conversion patterns from the Go spec — NEVER store in auintptrvariable across statementsweak.Pointer[T](Go 1.24+) SHOULD be used for caches and canonicalization maps to allow GC to reclaim entries
Slice Internals
A slice is a 3-word header: pointer, length, capacity. Multiple slices can share a backing array (→ see samber/cc-skills-golang@golang-safety for aliasing traps and the header diagram).
Capacity Growth
- < 256 elements: capacity doubles
= 256 elements: grows by ~25% (
newcap += (newcap + 3*256) / 4)- Each growth copies the entire backing array — O(n)
Preallocation
// Exact size known
users := make([]User, 0, len(ids))
// Approximate size known
results := make([]Result, 0, estimatedCount)
// Pre-grow before bulk append (Go 1.21+)
s = slices.Grow(s, additionalNeeded)slices Package (Go 1.21+)
Key functions: Sort/SortFunc, BinarySearch, Contains, Compact, Grow. For Clone, Equal, DeleteFunc → see samber/cc-skills-golang@golang-safety skill.
Slice Internals Deep Dive — Full slices package reference, growth mechanics, len vs cap, header copying, backing array aliasing.
Map Internals
Maps are hash tables with 8-entry buckets and overflow chains. They are reference types — assigning a map copies the pointer, not the data.
Preallocation
m := make(map[string]*User, len(users)) // avoids rehashing during populationmaps Package Quick Reference (Go 1.21+)
| Function | Purpose |
Collect (1.23+) | Build map from iterator |
Insert (1.23+) | Insert entries from iterator |
All (1.23+) | Iterator over all entries |
Keys, Values | Iterators over keys/values |
For Clone, Equal, sorted iteration → see samber/cc-skills-golang@golang-safety skill.
Map Internals Deep Dive — How Go maps store and hash data, bucket overflow chains, why maps never shrink (and what to do about it), comparing map performance to alternatives.
Arrays
Fixed-size, value types. Copied entirely on assignment. Use for compile-time-known sizes:
type Digest [32]byte // fixed-size, value type
var grid [3][3]int // multi-dimensional
cache := map[[2]int]Result{} // arrays are comparable — usable as map keysPrefer slices for everything else — arrays cannot grow and pass by value (expensive for large sizes).
container/ Standard Library
| Package | Data Structure | Best For |
container/list | Doubly-linked list | LRU caches, frequent middle insertion/removal |
container/heap | Min-heap (priority queue) | Top-K, scheduling, Dijkstra |
container/ring | Circular buffer | Rolling windows, round-robin |
bufio | Buffered reader/writer/scanner | Efficient I/O with small reads/writes |
Container types use any (no type safety) — consider generic wrappers. Container Patterns, bufio, and Examples — When to use each container type, generic wrappers to add type safety, and bufio patterns for efficient I/O.
strings.Builder vs bytes.Buffer
Use strings.Builder for pure string concatenation (avoids copy on String()), bytes.Buffer when you need io.Reader or byte manipulation. Both support Grow(n). Details and comparison
Generic Collections (Go 1.18+)
Use the tightest constraint possible. comparable for map keys, cmp.Ordered for sorting, custom interfaces for domain-specific ordering.
type Set[T comparable] map[T]struct{}
func (s Set[T]) Add(v T) { s[v] = struct{}{} }
func (s Set[T]) Contains(v T) bool { _, ok := s[v]; return ok }Writing Generic Data Structures — Using Go 1.18+ generics for type-safe containers, understanding constraint satisfaction, and building domain-specific generic types.
Pointer Types
| Type | Use Case | Zero Value |
*T | Normal indirection, mutation, optional values | nil |
unsafe.Pointer | FFI, low-level memory layout (6 spec patterns only) | nil |
weak.Pointer[T] (1.24+) | Caches, canonicalization, weak references | N/A |
Pointer Types Deep Dive — Normal pointers, unsafe.Pointer (the 6 valid spec patterns), and weak.Pointer[T] for GC-safe caches that don't prevent cleanup.
Copy Semantics Quick Reference
| Type | Copy Behavior | Independence |
int, float, bool, string | Value (deep copy) | Fully independent |
array, struct | Value (deep copy) | Fully independent |
slice | Header copied, backing array shared | Use slices.Clone |
map | Reference copied | Use maps.Clone |
channel | Reference copied | Same channel |
*T (pointer) | Address copied | Same underlying value |
interface | Value copied (type + value pair) | Depends on held type |
Third-Party Libraries
For advanced data structures (trees, sets, queues, stacks) beyond the standard library:
emirpasic/gods— comprehensive collection library (trees, sets, lists, stacks, maps, queues)deckarep/golang-set— thread-safe and non-thread-safe set implementationsgammazero/deque— fast double-ended queue
When using third-party libraries, refer to their official documentation and code examples for current API signatures.
- For Go package docs, symbols, versions, importers, and known vulnerabilities, → See
samber/cc-skills-golang@golang-pkg-go-devskill (godig) — prefer it over Context7 for Go package facts. - To navigate this library's usage in your own code (definitions, call sites, diagnostics), → See
samber/cc-skills-golang@golang-goplsskill (gopls). - Context7 remains a fallback for docs not indexed on pkg.go.dev.
Cross-References
- → See
samber/cc-skills-golang@golang-performanceskill for struct field alignment, memory layout optimization, and cache locality - → See
samber/cc-skills-golang@golang-safetyskill for nil map/slice pitfalls, append aliasing, defensive copying,slices.Clone/Equal - → See
samber/cc-skills-golang@golang-concurrencyskill for channels,sync.Map,sync.Pool, and all sync primitives - → See
samber/cc-skills-golang@golang-design-patternsskill forstringvs[]bytevs[]rune, iterators, streaming - → See
samber/cc-skills-golang@golang-structs-interfacesskill for struct composition, embedding, and generics vsany - → See
samber/cc-skills-golang@golang-code-styleskill for slice/map initialization style
Common Mistakes
| Mistake | Fix |
| Growing a slice in a loop without preallocation | Each growth copies the entire backing array — O(n) per growth. Use make([]T, 0, n) or slices.Grow |
Using container/list when a slice would suffice | Linked lists have poor cache locality (each node is a separate heap allocation). Benchmark first |
bytes.Buffer for pure string building | Buffer's String() copies the underlying bytes. strings.Builder avoids this copy |
unsafe.Pointer stored as uintptr across statements | GC can move the object between statements — the uintptr becomes a dangling reference |
| Large struct values in maps (copying overhead) | Map access copies the entire value. Use map[K]*V for large value types to avoid the copy |
References
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

