go
build_error
ai_generated
true
模式 embed.go:未找到匹配的文件
pattern embed.go: no matching files found
ID: go/embed-directive-file-not-found
92%修复率
86%置信度
1证据数
2023-08-01首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 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 | — | — | — |
根因分析
//go:embed 指令指定的文件或模式相对于源文件目录不存在,或者该文件被 .gitignore 或构建约束排除。
English
The //go:embed directive specifies a file or pattern that does not exist relative to the source file's directory, or the file is excluded by .gitignore or build constraints.
官方文档
https://pkg.go.dev/embed解决方案
-
确认文件相对于源文件存在;使用通配符如 "static/*" 来嵌入目录
-
如果文件是生成的,确保在构建前生成(例如,使用 go generate)
无效尝试
常见但无效的做法:
-
90% 失败
Go embed only supports relative paths (to the source file's directory); absolute paths are not allowed.
-
50% 失败
Gitignore does not affect Go's embed; the file must exist on disk at build time.