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 == "/" {
|
if path == "/" {
|
||||||
path = "/home"
|
path = "/home"
|
||||||
}
|
}
|
||||||
|
t, err := template.Must(template.ParseGlob("templates/*.html")).Clone()
|
||||||
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"))
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.NotFound(w, r)
|
http.NotFound(w, r)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if _, err := t.ParseFiles(filepath.Join("pages", path+".html")); err != nil {
|
||||||
err = tmpl.ExecuteTemplate(w, "layout", nil)
|
http.NotFound(w, r)
|
||||||
if err != nil {
|
return
|
||||||
|
}
|
||||||
|
if err := t.ExecuteTemplate(w, "layout", nil); err != nil {
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
http.HandleFunc("/", pageHandler)
|
http.HandleFunc("/", pageHandler)
|
||||||
|
|
||||||
log.Println("Server running at http://localhost:14888")
|
log.Println("Server running at http://localhost:14888")
|
||||||
log.Fatal(http.ListenAndServe(":14888", nil))
|
log.Fatal(http.ListenAndServe(":14888", nil))
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user