aboutsummaryrefslogtreecommitdiff
path: root/page/http.go
diff options
context:
space:
mode:
Diffstat (limited to 'page/http.go')
-rw-r--r--page/http.go58
1 files changed, 0 insertions, 58 deletions
diff --git a/page/http.go b/page/http.go
deleted file mode 100644
index b3622be..0000000
--- a/page/http.go
+++ /dev/null
@@ -1,58 +0,0 @@
-package page
-
-import (
- "log"
- "net/http"
- "path/filepath"
- "strings"
-)
-
-func SetupHandlers() {
- http.HandleFunc("/rebuildIndex/", RebuildIndexHandler)
- 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{Path: u}
- err := p.Render(w)
- if err != nil {
- if strings.HasSuffix(err.Error(), "no such file or directory") {
- log.Printf("Page '%s' not found, trying 404", p.Path)
- p.Path = "404"
- w.WriteHeader(404)
- err := p.Render(w)
- if err != nil {
- log.Println(err)
- http.Error(w, "Internal server error", 500)
- return
- }
- return
- } else {
- log.Println(err)
- http.Error(w, "Internal server error", 500)
- return
- }
- }
-
-}
-
-func RebuildIndexHandler(w http.ResponseWriter, r *http.Request) {
- if r.Method != "POST" {
- pageIndex = nil
- p := &Page{Path: "index"}
- _, _ = p.Index()
- }
- return
-}
-
-func StaticHandler() (h http.Handler) {
- return http.StripPrefix("/static/", http.FileServer(http.Dir("static")))
-}