Files
kisukalat.go/main.go

39 lines
739 B
Go

package main
import (
"html/template"
"log"
"net/http"
"path/filepath"
)
func pageHandler(w http.ResponseWriter, r *http.Request) {
path := r.URL.Path
if path == "/" {
path = "/home"
}
tmpl, err := template.ParseFiles(
filepath.Join("templates/layout.html"),
filepath.Join("templates/header.html"),
filepath.Join("templates/footer.html"),
filepath.Join("pages/"+path+".html"),
)
if err != nil {
http.NotFound(w, r)
return
}
err = tmpl.ExecuteTemplate(w, "layout", nil)
if 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))
}