From cddf7ed45147869a9d2eee2e40f59a97c472ea72 Mon Sep 17 00:00:00 2001 From: Mitch Riedstra Date: Sat, 26 Sep 2020 20:59:34 -0400 Subject: Split up http related stuff out of the page library. Make it an interface. Rename page to be 'local' reflecting that it reads the website off the local disk. Update the build script to include the go version. Switch to gorilla/mux Remove the convert command, since we're no longer utilizing that old layout or have any need to convert from it. --- page/http.go | 58 ---------------------------------------------------------- 1 file changed, 58 deletions(-) delete mode 100644 page/http.go (limited to 'page/http.go') 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"))) -} -- cgit v1.2.3