Skip to content

Instantly share code, notes, and snippets.

@itaysk
Last active April 29, 2020 09:44
Show Gist options
  • Save itaysk/f0a05b6cc8685721fd9ada9efa467553 to your computer and use it in GitHub Desktop.
Save itaysk/f0a05b6cc8685721fd9ada9efa467553 to your computer and use it in GitHub Desktop.
Embed file in Go using one line go generate
package main
import (
"encoding/base64"
"fmt"
)
//go:generate sh -c "(printf 'package main\nvar myfile string=`'; base64 myfile; printf '`') >myfile_generated.go"
func main() {
contents, _ := base64.StdEncoding.DecodeString(myfile)
fmt.Println(string(contents))
}
build:
go generate
go build
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment