aboutsummaryrefslogtreecommitdiff
path: root/cmd/web/handlers/blog.go
blob: 5a874f41372c89dbd39f079166834c6e039965a9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package handlers

import (
	"html/template"
	"log"
	"net/http"
)

func (ctx *HandlerContext) blogIndex(w http.ResponseWriter, r *http.Request) {
	if r.URL.Path != "/" {
		http.NotFound(w, r)
		return
	}

	files := []string{
		"./ui/html/base.tmpl.html",
		"./ui/html/pages/index.tmpl.html",
	}

	compiled, err := template.ParseFiles(files...)
	if err != nil {
		log.Println(err.Error())
		http.Error(w, "Internal Server Error", 500)
		return
	}

	err = compiled.ExecuteTemplate(w, "base", ctx)
	if err != nil {
		log.Println(err.Error())
		http.Error(w, "Internal Server Error", 500)
	}
}