/file2go

Commandline tool that recursively reads directories and files to generate go files containing byte slices.

Primary LanguageGoMIT LicenseMIT

file2go

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.

Instalation

go install github.com/ww9/file2go

Usage

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

Example of generated file

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!

Credits

https://github.com/hajimehoshi/file2byteslice for idea.

License

MIT