# Go Nil Map

> Map nil safety - read OK, write panics Use when this capability is needed.

- Skill: `tomevault-io/go-nil-map` (Agent Skill, multi-file: 2 files)
- Install (CLI): `npx skillmds@latest add tomevault-io/go-nil-map`
- Raw SKILL.md: https://api.skillmd.com/api/skills/tomevault-io/go-nil-map/raw
- Safety review: pending (external: skill-scanner PASS, skillspector PASS)
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: tomevault-io (https://skillmd.com/u/tomevault-io)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/tomevault-io/go-nil-map

---


# Map Nil Safety

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

## Pattern

### WRONG - Write to nil map
```go
var m map[string]int  // nil map
m["key"] = 42         // PANIC: assignment to entry in nil map
```

### CORRECT - Initialize with make
```go
m := make(map[string]int)
m["key"] = 42  // OK
```

### Reading is Safe
```go
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
```go
if m == nil {
    m = make(map[string]int)
}
m["key"] = 42
```

---
> Converted and distributed by [TomeVault](https://tomevault.io/claim/jamesprial) — claim your Tome and manage your conversions.
<!-- tomevault:4.0:skill_md:2026-04-13 -->

