Skip to content

therealplato/bake

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

github.com/therealplato/bake

Bake a file into a golang byte slice

I needed to deploy a source PNG along with a binary. I'd previously used go-bindata for embedding, but after auditing a project using code generated by go-bindata I realized that its output is quite complex.

I wanted something that solves my problem with fewer generated lines of code and less mental overhead.

If your problem involves embedding multiple files or frequently regenerating your embedded files, you'll probably prefer one of the alternatives listed below.

usage:

Give this tool a filename and it will produce baked.go in CWD, with a variable containing that file's bytes.

It will overwrite any existing baked.go file.

go install -v -u github.com/therealplato/bake
cd someproject
bake somefile
$EDITOR baked.go # change filename, package and variable name as needed

one way to manipulate the file:

var src bytes.Buffer
_, err := src.Write(baked)
if err != nil {
  log.Fatal(err)
}
// src is io.Reader

other projects solving similar problems:

https://github.com/hajimehoshi/file2byteslice (offers compression and CLI configuration)

https://github.com/rakyll/statik (requires runtime dependency)

https://github.com/kevinburke/go-bindata (there's other forks available, this is the one I've used)

https://github.com/dim13/file2go

About

bake your binary into a golang byte slice

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages