Skip to content

Instantly share code, notes, and snippets.

@satishbabariya
Created August 9, 2022 17:21
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 satishbabariya/16fd4f65844c378994dad8ea01038c18 to your computer and use it in GitHub Desktop.
Save satishbabariya/16fd4f65844c378994dad8ea01038c18 to your computer and use it in GitHub Desktop.
Go embed
package main
import (
"embed"
"io/fs"
"net/http"
)
//go:embed public
var content embed.FS
func handler() http.Handler {
fsys := fs.FS(content)
html, _ := fs.Sub(fsys, "public")
return http.FileServer(http.FS(html))
}
func main() {
mux := http.NewServeMux()
mux.Handle("/", handler())
http.ListenAndServe(":8080", mux)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment