# 恐慌：运行时错误：向空通道发送数据

- **ID:** `go/nil-channel-send`
- **领域:** go
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

尝试向未使用make初始化的空通道发送数据

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 1.18 | active | — | — |
| 1.21 | active | — | — |

## 解决方案

1. **Initialize channel with make before any send operation** (95% 成功率)
   ```
   ch := make(chan int, 10)
ch <- 42
   ```
2. **Use sync.Once to ensure channel initialization is done once** (90% 成功率)
   ```
   var once sync.Once
var ch chan int
once.Do(func() {
    ch = make(chan int)
})
ch <- 42
   ```

## 无效尝试

- **Using a global variable without initialization** — Global channel variables default to nil; forgetting to initialize with make leads to panic (90% 失败率)
- **Assuming channel is initialized after function returns** — If the channel is assigned inside a goroutine, it may still be nil when another goroutine tries to send (80% 失败率)
