Skip to content

Instantly share code, notes, and snippets.

@itaysk
Last active April 30, 2020 15:32
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 itaysk/26d87458a5f0530449c26fa2ccc33567 to your computer and use it in GitHub Desktop.
Save itaysk/26d87458a5f0530449c26fa2ccc33567 to your computer and use it in GitHub Desktop.
Embed file in Go using go link flag
package main
import (
"encoding/base64"
"fmt"
)
var myfile string
func main() {
contents, _ := base64.StdEncoding.DecodeString(myfile)
fmt.Println(string(contents))
}
b64contents = $(shell base64 -w 0 myfile)
build:
go build -ldflags "-X main.myfile=$(b64contents)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment