I have some text file that I read from my Go program. I\'d like to ship a single executable, without supplying that text file additionally. How do I embed it into compilatio
Was looking for the same thing and came across esc: Embedding Static Assets in Go (by 19 Nov 2014) where author, Matt Jibson, is evaluating 3 other popular packages that claims to do file embedding:
and explain why he eventually come up with his own package:
So after briefly trying them all (in that order) I've naturally settled on Matt's esc as it was the only one that was working out of the box with necessary for me functionality, namely:
//go:generate instead of forcing you to manually write additional Go codeThe point #2 was important for me and the rest of the packages for one reason or another didn't work out that well.
From esc's README:
esc embeds files into go programs and provides http.FileSystem interfaces to them.
It adds all named files or files recursively under named directories at the path specified. The output file provides an http.FileSystem interface with zero dependencies on packages outside the standard library.