go-data-structures

Explain Go allocation primitives and data structures with idiomatic examples.

Updated Feb 28, 2026
One-click install
npx skills add https://github.com/phant-app/phant --skill go-data-structures-phant-app
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: go-data-structures
Source: https://github.com/phant-app/phant/tree/main/.agents/skills/go-data-structures
Command: npx skills add https://github.com/phant-app/phant --skill go-data-structures-phant-app

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Go developers often struggle with when and how to allocate data structures, and with choosing the right primitives (new vs make). This guide clarifies core Go data structures, allocation rules, and common usage patterns to reduce bugs and improve performance.

Core Features & Use Cases

  • Allocation primitives: choose between new and make for pointers, slices, maps, and channels, with idiomatic examples.

  • Slices, arrays, maps: explain lifetime, copying behavior, and common pitfalls like aliasing and capacity.

  • Printing and formatting: use fmt to render values and understand zero values and composite literals.

  • Use Case: Build memory-efficient data containers, implement data-processing pipelines, and initialize complex structs with clear semantics.

Quick Start

Experiment with a small Go snippet that allocates a slice with make and a pointer with new to observe differences.

Frequently Asked Questions about go-data-structures

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

FAQPage Schema
What is the difference between new and make when allocating Go data structures?

The difference between new and make is that new allocates zero-valued memory returning a pointer, while make initializes built-in Go data structures like slices, maps, and channels with proper internal allocation and non-nil values.

How do I avoid slice aliasing and capacity bugs in Go?

To avoid slice aliasing and capacity bugs in Go, you must understand slice lifetime and copying behavior. Using explicit copy operations prevents unintended memory sharing when appending or modifying underlying arrays.

What's the best way to initialize Go maps and slices using composite literals?

The best way to initialize Go maps and slices is using composite literals. This approach explicitly defines zero values and initial key-value pairs or elements, ensuring clear semantics when building memory-efficient data containers.

How do I use iota for constants in Go programs?

You use iota in Go programs to generate incrementing constants. It simplifies defining enumerated values by resetting to zero in each const block, reducing bugs related to manual integer assignment.

Why does my Go fmt printing show unexpected zero values for structures?

Go fmt printing shows zero values because newly allocated structures default to empty states. Understanding how printing and formatting render these defaults clarifies allocation primitive behavior and struct initialization semantics.