33 lines or so. please think i am cool guys
This commit is contained in:
18
main.go
18
main.go
@@ -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()
|
||||
if err != nil {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
_, err = tmpl.ParseFiles(filepath.Join("pages", path+".html"))
|
||||
t, err := template.Must(template.ParseGlob("templates/*.html")).Clone()
|
||||
if err != nil {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
err = tmpl.ExecuteTemplate(w, "layout", nil)
|
||||
if err != nil {
|
||||
if _, err := t.ParseFiles(filepath.Join("pages", path+".html")); err != nil {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
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))
|
||||
}
|
||||
|
Reference in New Issue
Block a user