Daily Archives: 09.03.2021
Embedding assets to go binary in go 1.16
That’s how you can use it:
1 2 3 4 5 6 7 8 9 10 |
package server import "embed" // content holds our static web server content. //go:embed image/* template/* //go:embed html/index.html var content embed.FS data, _ := f.ReadFile("html/index.html") print(string(data)) |
Or embedding one file directly into a variable:
1 2 3 4 5 |
import _ "embed" //go:embed hello.txt var s string print(s) |
More details — https://golang.org/pkg/embed/