Gotcha: referencing symlinks with go:embed
result in irregular file
errors

Early in 2024, I hit an issue with Go not allowing me to use go:embed
.
(Aside: this is one of those posts that has been on the backburner and I'm finally getting around to it given I had a few minutes spare, and I want to test some new functionality in my blog-to-LinkedIn syndication.)
I can't remember the full details for what I was exactly doing, but I remember having a set of files such as:
% ls -al
total 20
drwxr-xr-x 2 jamie jamie 4096 Sep 10 15:00 .
drwx------ 3 jamie jamie 4096 Sep 10 14:59 ..
-rw-r--r-- 1 jamie jamie 12262 Sep 10 15:00 favicon.png
lrwxrwxrwx 1 jamie jamie 52 Sep 10 14:59 profile.png -> /home/jamie/workspaces/jvt.me/static/img/profile.png
With this, I was then using the excellent go:embed
functionality, like so:
package main
import (
_ "embed"
"fmt"
)
}
//go:embed static/*.png
var images embed.FS
// ...
This was giving me a rather obtuse error:
main.go:11:12: pattern static/*.png: cannot embed irregular file static/profile.png
Upon further digging, it was down to the fact that I had many files that were fine, and one of which was a symlink (aka symbolic link), which was tripping up Go.
It turns out it has been fixed upstream but only if opting in to this behaviour with i.e.:
env GODEBUG=embedfollowsymlinks=1 go build
This only appears in Go 1.25+.