go-data-structures

Select Go data structures for slices, maps, arrays, and strings.

8|Updated Jun 5, 2026
One-click install
npx skills add https://github.com/muratmirgun/gophers --skill go-data-structures-muratmirgun
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: go-data-structures
Source: https://github.com/muratmirgun/gophers/tree/main/skills/go-data-structures
Command: npx skills add https://github.com/muratmirgun/gophers --skill go-data-structures-muratmirgun

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill helps you choose and use the right Go data structure for each access pattern, avoiding aliasing bugs, unnecessary allocations, and inefficient container choices.

Core Features & Use Cases

  • Slice and map correctness: Understand header copying, aliasing, cloning, append behavior, and safe preallocation.
  • Performance-oriented selection: Pick slices, maps, arrays, strings.Builder, bytes.Buffer, or container/* types based on the workload.
  • Modern Go helpers: Apply the slices and maps standard packages for cloning, searching, sorting, deletion, and growth.
  • Use case: When building an API response, you can choose empty slices for JSON output, clone shared data before returning it, and pre-size maps and slices to reduce reallocations.

Quick Start

Ask the skill to review your Go data structure choice for the current code and recommend the safest, most efficient slice, map, string, or container pattern.

Frequently Asked Questions about go-data-structures

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I prevent slice aliasing bugs when copying Go data structures?

To prevent slice aliasing bugs in Go data structures, you must clone shared data before returning it and safely reassign the result of append operations to avoid unexpected memory sharing.

When should I preallocate Go maps and slices for better performance?

You should preallocate Go maps and slices when you know the expected capacity in advance, which eliminates repeated memory reallocations and reduces GC overhead during collection tasks.

What is the best way to choose between bytes.Buffer and strings.Builder in Go?

Choosing between bytes.Buffer and strings.Builder in Go depends on your workload; strings.Builder is optimal for read-only string concatenation, while bytes.Buffer supports byte slice mutations.

How do I use the modern Go slices and maps packages for sorting and deletion?

You use the modern Go slices and maps packages to perform efficient cloning, searching, sorting, and deletion on collections without writing boilerplate comparison logic.

How do I ensure Go API responses output empty JSON arrays instead of null?

To ensure Go API responses output empty JSON arrays instead of null, you must initialize empty slices before marshaling, which guarantees correct JSON-facing API behavior.

Why does my Go append function lose data when modifying a shared slice?

Your Go append function loses data because append creates a new underlying array if capacity is exceeded; you must reassign the returned slice to update the header and reflect changes.