Last active
April 29, 2020 09:44
-
-
Save itaysk/f0a05b6cc8685721fd9ada9efa467553 to your computer and use it in GitHub Desktop.
Embed file in Go using one line go generate
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
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)) | |
} |
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
build: | |
go generate | |
go build |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment