Last active
March 10, 2021 09:18
-
-
Save bennyng/cc6fccc2d90ec3b64f31a1dec157c2f1 to your computer and use it in GitHub Desktop.
simple go http serving embedded static assets
This file contains 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 ( | |
"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