33 lines or so. please think i am cool guys

This commit is contained in:
2025-09-24 14:46:36 +03:00
parent 09aa419694
commit cf61021c67

12
main.go
View File

@@ -12,28 +12,22 @@ func pageHandler(w http.ResponseWriter, r *http.Request) {
if path == "/" {
path = "/home"
}
tmpl, err := template.Must(template.ParseGlob("templates/*.html")).Clone()
t, err := template.Must(template.ParseGlob("templates/*.html")).Clone()
if err != nil {
http.NotFound(w, r)
return
}
_, err = tmpl.ParseFiles(filepath.Join("pages", path+".html"))
if err != nil {
if _, err := t.ParseFiles(filepath.Join("pages", path+".html")); err != nil {
http.NotFound(w, r)
return
}
err = tmpl.ExecuteTemplate(w, "layout", nil)
if err != nil {
if err := t.ExecuteTemplate(w, "layout", nil); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
}
func main() {
http.HandleFunc("/", pageHandler)
log.Println("Server running at http://localhost:14888")
log.Fatal(http.ListenAndServe(":14888", nil))
}