# 不允许的导入循环
包 A
	导入 B
	导入 A

- **ID:** `go/missing-import-cycle-with-init`
- **领域:** go
- **类别:** build_error
- **验证级别:** ai_generated
- **修复率:** 85%

## 根因

两个或多个包直接或间接相互导入，创建了 Go 编译器无法解析的循环依赖。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| go1.20 | active | — | — |
| go1.21 | active | — | — |
| go1.22 | active | — | — |

## 解决方案

1. ```
   Extract the shared types or interfaces into a third package that both A and B import
   ```
2. ```
   Use dependency injection: pass interfaces from A to B instead of importing A directly in B
   ```

## 无效尝试

- **Using a blank import (_ "package") to break the cycle** — Blank imports only trigger init() functions, they don't resolve the circular dependency in the type system. (95% 失败率)
- **Moving all code into a single package** — Violates separation of concerns; makes the codebase monolithic and harder to maintain. (80% 失败率)
- **Adding a new import that re-exports types from the cycle** — Creates a longer cycle or introduces a third package that still depends on the cycle. (90% 失败率)
