summary refs log tree commit diff stats
path: root/handlers.go
diff options
context:
space:
mode:
authorBen Morrison <ben@gbmor.dev>2019-05-21 23:44:03 -0400
committerBen Morrison <ben@gbmor.dev>2019-05-22 00:26:16 -0400
commit37be25ffddafdf5b7ed4c86b25e3e1ad3a6b3362 (patch)
tree63dcbc8d46e1c5089fc339bc2ad07745a9d4e51b /handlers.go
parent54a4f6f720979dc8c8d6224acd24f04d147ef761 (diff)
downloadgetwtxt-37be25ffddafdf5b7ed4c86b25e3e1ad3a6b3362.tar.gz
tuning query handling
Diffstat (limited to 'handlers.go')
-rw-r--r--handlers.go41
1 files changed, 33 insertions, 8 deletions
diff --git a/handlers.go b/handlers.go
index 2bf74f8..947c96a 100644
--- a/handlers.go
+++ b/handlers.go
@@ -7,6 +7,7 @@ import (
 	"log"
 	"net/http"
 	"os"
+	"strings"
 
 	"github.com/gorilla/mux"
 )
@@ -75,19 +76,21 @@ func apiEndpointHandler(w http.ResponseWriter, r *http.Request) {
 	// if there's no query, return everything in
 	// registry for a given endpoint
 	var out []string
-	if r.URL.Path == "/api/plain/users" {
+	switch r.URL.Path {
+	case "/api/plain/users":
 		out, err = twtxtCache.QueryUser("")
-	} else if r.URL.Path == "/api/plain/mentions" {
+
+	case "/api/plain/mentions":
 		out, err = twtxtCache.QueryInStatus("@<")
-	} else {
+
+	default:
 		out, err = twtxtCache.QueryAllStatuses()
 	}
-	if err != nil {
-		log500(w, r, err)
-		return
-	}
 
 	data := parseQueryOut(out)
+	if err != nil {
+		data = []byte("")
+	}
 
 	w.Header().Set("Content-Type", txtutf8)
 
@@ -133,11 +136,33 @@ func apiTagsHandler(w http.ResponseWriter, r *http.Request) {
 	vars := mux.Vars(r)
 	tags := vars["tags"]
 
-	out, err := twtxtCache.QueryInStatus(tags)
+	out, err := twtxtCache.QueryInStatus("#" + tags)
+	if err != nil {
+		log500(w, r, err)
+		return
+	}
+	tags = strings.ToLower(tags)
+	out2, err := twtxtCache.QueryInStatus("#" + tags)
+	if err != nil {
+		log500(w, r, err)
+		return
+	}
+	tags = strings.Title(tags)
+	out3, err := twtxtCache.QueryInStatus("#" + tags)
 	if err != nil {
 		log500(w, r, err)
 		return
 	}
+	tags = strings.ToUpper(tags)
+	out4, err := twtxtCache.QueryInStatus("#" + tags)
+	if err != nil {
+		log500(w, r, err)
+		return
+	}
+
+	out = append(out, out2...)
+	out = append(out, out3...)
+	out = append(out, out4...)
 
 	data := parseQueryOut(out)