smithery/JamesPrial

go-nil-map

Map nil safety - read OK, write panics

Installation

$ npx skills add smithery/JamesPrial --skill go-nil-map

Also in this package

Other skills from smithery/JamesPrial · top by installs.

npx skills add smithery/JamesPrial

Browse all from smithery/JamesPrial

More details

Agent compatibility

Declared targets from SKILL.md / docs. Unmarked agents are not listed — the skill may still install via the CLI.

Claude Code Not declared
Cursor Not declared
Codex Not declared
GitHub Copilot Not declared
Windsurf Not declared
Gemini CLI Not declared
Cline Not declared
OpenCode Not declared

Package contents

Files included with this skill beyond the listing page.

  • skill md SKILL.md 840 B
  • docs SUMMARY.md 56 B

History

  1. First recorded snapshot · 0 installs

SKILL.md

Map Nil Safety

Problem

Reading from nil map returns zero value. Writing to nil map panics.

Pattern

WRONG - Write to nil map

var m map[string]int  // nil map
m["key"] = 42         // PANIC: assignment to entry in nil map

CORRECT - Initialize with make

m := make(map[string]int)
m["key"] = 42  // OK

Reading is Safe

var m map[string]int  // nil map
v := m["key"]         // OK, v = 0 (zero value)
v, ok := m["key"]     // OK, v = 0, ok = false

Quick Fix

  • Always initialize maps with make() before writing
  • Check if map is nil before range/write
  • Reading from nil map is safe but returns zero values

Defensive Pattern

if m == nil {
    m = make(map[string]int)
}
m["key"] = 42