diff --git a/cmd/web/handlers.go b/cmd/web/handlers.go index 9de0073..ca36a67 100644 --- a/cmd/web/handlers.go +++ b/cmd/web/handlers.go @@ -2,6 +2,8 @@ package main import ( "fmt" + "html/template" + "log" "net/http" "strconv" ) @@ -11,7 +13,22 @@ func home(w http.ResponseWriter, r *http.Request) { http.NotFound(w, r) return } - w.Write([]byte("Hello from Snippetbox")) + files := []string{ + "./ui/html/base.tmpl", + "./ui/html/partials/nav.tmpl", + "./ui/html/pages/home.tmpl", + } + ts, err := template.ParseFiles(files...) + if err != nil { + log.Print(err.Error()) + http.Error(w, "Internal Server Error", http.StatusInternalServerError) + return + } + err = ts.ExecuteTemplate(w, "base", nil) + if err != nil { + log.Print(err.Error()) + http.Error(w, "Internal Server Error", http.StatusInternalServerError) + } } func snippetView(w http.ResponseWriter, r *http.Request) { diff --git a/ui/html/base.tmpl b/ui/html/base.tmpl new file mode 100644 index 0000000..a22d752 --- /dev/null +++ b/ui/html/base.tmpl @@ -0,0 +1,19 @@ +{{define "base"}} + + +
+ +There's nothing to see here yet!
+{{end}} \ No newline at end of file diff --git a/ui/html/partials/nav.tmpl b/ui/html/partials/nav.tmpl new file mode 100644 index 0000000..ee7efd3 --- /dev/null +++ b/ui/html/partials/nav.tmpl @@ -0,0 +1,5 @@ +{{define "nav"}} + +{{end}} \ No newline at end of file