about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorBen Morrison <ben@gbmor.dev>2020-05-09 01:29:27 -0400
committerBen Morrison <ben@gbmor.dev>2020-05-09 01:29:27 -0400
commit21633380cd3010423821a78d34db2c0fb4a740a7 (patch)
tree6a1ed1b724149d95594f30feb6d2814eb631cac4
parent460684d77834d65fa47f3534056baa72dfba17ec (diff)
downloadapi-21633380cd3010423821a78d34db2c0fb4a740a7.tar.gz
eliminated discrete handler for index page
-rw-r--r--http.go32
1 files changed, 5 insertions, 27 deletions
diff --git a/http.go b/http.go
index 358efce..a2948f7 100644
--- a/http.go
+++ b/http.go
@@ -4,7 +4,6 @@ import (
 	"errors"
 	"net/http"
 	"strings"
-	"time"
 )
 
 const mimePlain = "text/plain; charset=utf-8"
@@ -20,13 +19,8 @@ func mainHandler(w http.ResponseWriter, r *http.Request) {
 		return
 	}
 
-	if r.URL.Path == "/" {
-		indexHandler(w, r)
-		return
-	}
-
 	format := formatHop(r)
-	if format != "plain" && format != "json" {
+	if format != "plain" && format != "json" && r.URL.Path != "/" {
 		errHTTP(w, r, errors.New("400 Bad Request"), http.StatusBadRequest)
 		return
 	}
@@ -57,6 +51,10 @@ func methodHop(r *http.Request) bool {
 
 // Yoinks the response format
 func formatHop(r *http.Request) string {
+	if r.URL.Path == "/" {
+		return ""
+	}
+
 	split := strings.Split(r.URL.Path[1:], "/")
 	return split[0]
 }
@@ -66,23 +64,3 @@ func routingHop(r *http.Request) string {
 	split := strings.Split(r.URL.Path[1:], "/")
 	return split[1]
 }
-
-// Yeets the index/summary page to the user
-func indexHandler(w http.ResponseWriter, r *http.Request) {
-	cache.bap("/")
-	cache.RLock()
-	defer cache.RUnlock()
-
-	out := cache.pages["/"].raw
-	expires := cache.pages["/"].expires
-
-	w.Header().Set("Content-Type", mimePlain)
-	w.Header().Set("Expires", expires.Format(time.RFC1123))
-
-	_, err := w.Write(out)
-	if err != nil {
-		errHTTP(w, r, err, http.StatusInternalServerError)
-		return
-	}
-	log200(r)
-}