aboutsummaryrefslogtreecommitdiff
path: root/page/http.go
blob: acf9147ac3b64bcf6b01ab41125c8f564d47ae87 (plain) (blame)
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
33
34
package page

import (
	"log"
	"net/http"
	"path/filepath"
)

func SetupHandlers() {
	http.Handle("/static/", StaticHandler())
	http.HandleFunc("/", PageHandler)
}

func PageHandler(w http.ResponseWriter, r *http.Request) {
	u := r.URL.Path
	if u == "/" {
		u = "/index"
	}
	u = filepath.Join(".", u)
	log.Println(u)

	p := &Page{Name: u}
	err := p.Render(w)
	if err != nil {
		log.Println(err)
		http.Error(w, "Internal server error", 500)
		return
	}

}

func StaticHandler() (h http.Handler) {
	return http.StripPrefix("/static/", http.FileServer(http.Dir("static")))
}