# 模式 embed.go：未找到匹配的文件

- **ID:** `go/embed-directive-file-not-found`
- **领域:** go
- **类别:** build_error
- **验证级别:** ai_generated
- **修复率:** 92%

## 根因

//go:embed 指令指定的文件或模式相对于源文件目录不存在，或者该文件被 .gitignore 或构建约束排除。

## 版本兼容性

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

## 解决方案

1. ```
   确认文件相对于源文件存在；使用通配符如 "static/*" 来嵌入目录
   ```
2. ```
   如果文件是生成的，确保在构建前生成（例如，使用 go generate）
   ```

## 无效尝试

- **** — Go embed only supports relative paths (to the source file's directory); absolute paths are not allowed. (90% 失败率)
- **** — Gitignore does not affect Go's embed; the file must exist on disk at build time. (50% 失败率)
