Created
March 29, 2024 20:07
-
-
Save greg-hellings/89a2952dff4b1e3f243a9bd59762b4c8 to your computer and use it in GitHub Desktop.
This file contains hidden or 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" | |
"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