Skip to content

Instantly share code, notes, and snippets.

@dtoebe
Created January 3, 2017 11:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dtoebe/3b651f4757403d2b9875510eff90fda1 to your computer and use it in GitHub Desktop.
Save dtoebe/3b651f4757403d2b9875510eff90fda1 to your computer and use it in GitHub Desktop.
EMBED OTHER BINARIES IN GOLANG BINARY - main.go - 2
// ./main.go
package main
import "os"
// When we run `go generate` from the cli it will run the
// `go run` command outlined below
// **Important: sure to include the comment below for the generator to see**
//go:generate go run generators/generator.go
//This func takes the name that you want the generated []byte to be as a binary
func genFile(p string) (int, error) {
//Create the binary file
file, err := os.Create(p)
if err != nil {
return 0, err
}
defer file.Close()
//Write the data to the the created file
return file.Write(data)
}
func main() {
p := "./final-bin"
genFile(p)
//Finally make the file executable
//I know... 777 is bad
os.Chmod(p, 0777)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment