feat: html static templates

This commit is contained in:
ange 2024-12-14 08:34:47 +00:00
parent 9d0da00371
commit e9fc659a5a
Signed by: ange
GPG key ID: 9E0C4157BB7BEB1D
12 changed files with 91 additions and 100 deletions

View file

@ -2,15 +2,15 @@ package main
import (
"net/http"
"path/filepath"
)
func index(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, filepath.Join("html", "index.html"))
r.URL.Path = "/contact"
html(w, r)
}
func style(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, "/html/style.css")
http.ServeFile(w, r, "html/style.css")
}
func static(w http.ResponseWriter, r *http.Request) {
@ -18,5 +18,9 @@ func static(w http.ResponseWriter, r *http.Request) {
}
func html(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, filepath.Join("html", r.URL.Path + ".html"))
if t, found := TMPL[r.URL.Path]; found {
w.Write(t)
} else {
http.NotFound(w, r)
}
}