Go 1.16: //go:embed changes everything for CLI tools
Posted by Surya Narayan · 2021-04-16
Static assets embedded in the binary. No more rice or packr. This is how I'm embedding SQL migrations and HTML templates now. One binary, zero runtime dependencies. https://github.com/golang/go/releases/tag/go1.16
package main
import (
"embed"
"net/http"
)
//go:embed static/*
var staticFiles embed.FS
//go:embed migrations/*.sql
var migrations embed.FS
func main() {
http.Handle("/", http.FileServer(http.FS(staticFiles)))
http.ListenAndServe(":8080", nil)
}