Skip to content

Instantly share code, notes, and snippets.

@greg-hellings
Created March 29, 2024 20:07
Show Gist options
  • Save greg-hellings/89a2952dff4b1e3f243a9bd59762b4c8 to your computer and use it in GitHub Desktop.
Save greg-hellings/89a2952dff4b1e3f243a9bd59762b4c8 to your computer and use it in GitHub Desktop.
package main
import (
"embed"
"fmt"
"log"
"net/http"
)
//go:embed assets/*
var assets embed.FS
func main() {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
path := r.URL.Path
if path == "/" {
path = "/index.html"
}
data, err := assets.ReadFile(path)
if err != nil {
w.WriteHeader(http.StatusNotFound)
fmt.Fprintf(w, "File not found: %s", path)
return
}
w.WriteHeader(http.StatusOK)
w.Write(data)
})
log.Fatal(http.ListenAndServe(":8080", nil))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment