go-data-structures

Explain Go data structures, allocation primitives, and iota to developers.

Updated Apr 16, 2026
One-click install
npx skills add https://github.com/HadiCherkaoui/opencode-config --skill go-data-structures-hadicherkaoui
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: go-data-structures
Source: https://github.com/HadiCherkaoui/opencode-config/tree/main/skills/golang/go-data-structures
Command: npx skills add https://github.com/HadiCherkaoui/opencode-config --skill go-data-structures-hadicherkaoui

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Go developers often struggle to understand the nuances of Go's data structures, memory allocation primitives, and common patterns.

Core Features & Use Cases

  • Allocation primitives: new vs make; slices, arrays, maps basics; printing with fmt; constants with iota; composite literals; common gotchas.
  • Practical guidance for selecting appropriate data structures in real-world Go programs.
  • Use cases include onboarding new teammates, code reviews, and learning exercises.

Quick Start

Experiment with the code samples in this skill to see how new vs make allocate and how slices, maps, and arrays behave in real Go programs.

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 for memory allocation in Go?

In Go memory allocation, new returns a pointer to a zero-initialized value, while make initializes and returns a ready-to-use slice, map, or channel. Use make for built-in data structures and new for struct pointers.

How do slices and arrays behave differently in Go programs?

Go arrays have fixed sizes determined at compile time, whereas Go slices are dynamic views over arrays. Slices handle memory allocation automatically and support appending elements, making them more flexible for real-world Go programs.

What are common gotchas when working with Go maps and slices?

Common Go gotchas include slice aliases sharing underlying arrays causing unexpected mutations, maps causing concurrent read/write panics, and nil maps returning zero values but panicking on writes during memory allocation.

How does iota work when defining constants in Go?

Iota is a Go compiler constant generator that increments by one for each line in a constant declaration block. It simplifies defining enumerated types and bitwise flags, resetting to zero in each new const block.

What is the best way to print Go data structures for debugging?

Use the fmt package with verbs like %v for default formatting, %+v for struct field names, and %#v for complete Go syntax representation. This accurately displays slice, map, and array structures during debugging.

Can I use composite literals to initialize Go data structures?

Yes, composite literals initialize Go data structures directly by specifying values in braces. They efficiently create and populate arrays, slices, maps, and structs without requiring separate memory allocation calls.