# http: /api/v1/users 的重复注册

- **ID:** `go/http-multiple-registrations`
- **领域:** go
- **类别:** build_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

相同的 URL 模式多次注册到 http.Handle 或 http.HandleFunc，导致 panic。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 1.19 | active | — | — |
| 1.22 | active | — | — |

## 解决方案

1. **** (90% 成功率)
   ```
   Check if pattern is already registered before adding: if _, exists := mux.Handlers()[pattern]; !exists { mux.Handle(pattern, handler) }
   ```
2. **** (85% 成功率)
   ```
   Use a single handler with method-based routing: http.HandleFunc("/api/v1/users", func(w http.ResponseWriter, r *http.Request) { switch r.Method { case "GET": ... case "POST": ... } })
   ```

## 无效尝试

- **** — Go panics on duplicate registration; this is not allowed. (100% 失败率)
- **** — Overriding can lead to unexpected behavior and is not idiomatic. (50% 失败率)
