Back to list
JamesPrial

go-nil-map

by JamesPrial

WIP - collection of various Claude stuff i make/use/have_Claude_hallucinate

2🍴 0📅 Jan 23, 2026

SKILL.md


name: go-nil-map description: Map nil safety - read OK, write panics

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

Score

Total Score

65/100

Based on repository quality metrics

SKILL.md

SKILL.mdファイルが含まれている

+20
LICENSE

ライセンスが設定されている

+10
説明文

100文字以上の説明がある

0/10
人気

GitHub Stars 100以上

0/15
最近の活動

1ヶ月以内に更新

+10
フォーク

10回以上フォークされている

0/5
Issue管理

オープンIssueが50未満

+5
言語

プログラミング言語が設定されている

+5
タグ

1つ以上のタグが設定されている

+5

Reviews

💬

Reviews coming soon