Commandline tool that recursively reads directories and files to generate go files containing byte slices.
Useful for embedding static files inside self-contained go programs.
go install github.com/ww9/file2go
Generate for a single file:
file2go file.css
Outputs:
style.css => style.css.go
Generate for all files in directory and subdirectories:
file2go assets
Outputs:
assets/style.css => assets/style.css.go
assets/music.mp3 => assets/music.mp3.go
Optional -prefix argument inserts a string at the top of every generated go file:
file2go -prefix "// Automatically generated by file2go" assets
package assets
var Bstyle_css = []byte("\xff\xd8\xff\xe0\x00\x10JFIF\x00\x01\x01...")
You can then import these packages in your main.go and use the byte slice variables. When you compile the program, it will contain all embedded files. No need to distribute assets folder!
https://github.com/hajimehoshi/file2byteslice for idea.
MIT