Created
January 3, 2017 11:30
-
-
Save dtoebe/3b651f4757403d2b9875510eff90fda1 to your computer and use it in GitHub Desktop.
EMBED OTHER BINARIES IN GOLANG BINARY - main.go - 2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ./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