# 不允许导入循环：包 main 导入了自身

- **ID:** `go/self-import-cycle`
- **领域:** go
- **类别:** build_error
- **验证级别:** ai_generated
- **修复率:** 90%

## 根因

一个包直接或间接地导入了自身，造成了 Go 编译器无法解决的依赖循环。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| Go 1.18 | active | — | — |
| Go 1.19 | active | — | — |
| Go 1.20 | active | — | — |
| Go 1.21 | active | — | — |
| Go 1.22 | active | — | — |

## 解决方案

1. ```
   将共享的类型或函数提取到第三个包中，让原始的两个包都导入该包
   ```
2. ```
   使用接口反转依赖：在一个包中定义接口，在另一个包中实现它
   ```

## 无效尝试

- **** — Files in the same package cannot import the package; they share the same namespace. (90% 失败率)
- **** — Blank import still triggers the import mechanism and does not resolve the cycle. (85% 失败率)
