diff options
Diffstat (limited to 'page/http.go')
| -rw-r--r-- | page/http.go | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/page/http.go b/page/http.go new file mode 100644 index 0000000..acf9147 --- /dev/null +++ b/page/http.go @@ -0,0 +1,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"))) +} |
