Skip to content

Instantly share code, notes, and snippets.

@bennyng
Last active March 10, 2021 09:18
Show Gist options
  • Save bennyng/cc6fccc2d90ec3b64f31a1dec157c2f1 to your computer and use it in GitHub Desktop.
Save bennyng/cc6fccc2d90ec3b64f31a1dec157c2f1 to your computer and use it in GitHub Desktop.
simple go http serving embedded static assets
package main
import (
"embed"
"log"
"net/http"
)
//go:embed _app/* font/* img/*
//go:embed favicon.ico
//go:embed index.html
var static embed.FS //nolint:gochecknoglobals
func main() {
staticFS := http.FS(static)
fs := http.FileServer(staticFS)
http.Handle("/", fs)
log.Println("Listening on :3000")
err := http.ListenAndServe(":3000", nil)
if err != nil {
log.Fatal(err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment