summary refs log tree commit diff stats
path: root/svc
diff options
context:
space:
mode:
authorBen Morrison <ben@gbmor.dev>2019-08-28 16:10:01 -0400
committerBen Morrison <ben@gbmor.dev>2019-08-28 16:10:01 -0400
commit910e69ac1b504ba0b9616d84280690c719cfaa3c (patch)
treeafd08e17d12b4638d1bd8dad6bfc580bbbe4ed54 /svc
parent0862bfa13c77484461eb96b2d94180d835ef2805 (diff)
downloadgetwtxt-910e69ac1b504ba0b9616d84280690c719cfaa3c.tar.gz
endpoint for version response v0.4.5
Diffstat (limited to 'svc')
-rw-r--r--svc/handlers.go12
-rw-r--r--svc/svc.go2
2 files changed, 13 insertions, 1 deletions
diff --git a/svc/handlers.go b/svc/handlers.go
index 5a46521..bd9ec62 100644
--- a/svc/handlers.go
+++ b/svc/handlers.go
@@ -141,6 +141,18 @@ func apiEndpointHandler(w http.ResponseWriter, r *http.Request) {
 		out, err = twtxtCache.QueryAllStatuses()
 		out = registry.ReduceToPage(page, out)
 
+	case "/api/plain/version":
+		etag := fmt.Sprintf("%x", sha256.Sum256([]byte(Vers)))
+		w.Header().Set("ETag", "\""+etag+"\"")
+		w.Header().Set("Content-Type", txtutf8)
+		_, err := w.Write([]byte(strings.TrimSpace("getwtxt " + Vers)))
+		if err != nil {
+			errHTTP(w, r, err, http.StatusInternalServerError)
+			return
+		}
+		log200(r)
+		return
+
 	default:
 		errHTTP(w, r, fmt.Errorf("endpoint not found"), http.StatusNotFound)
 		return
diff --git a/svc/svc.go b/svc/svc.go
index b20ac7a..8b5c113 100644
--- a/svc/svc.go
+++ b/svc/svc.go
@@ -123,7 +123,7 @@ func setEndpointRouting(api *mux.Router) {
 
 	// Specifying the endpoint with and without query information.
 	// Will return 404 on empty queries otherwise.
-	api.Path("/{format:(?:plain)}/{endpoint:(?:mentions|users|tweets)}").
+	api.Path("/{format:(?:plain)}/{endpoint:(?:mentions|users|tweets|version)}").
 		Methods("GET", "HEAD").
 		HandlerFunc(apiEndpointHandler)
 	api.Path("/{format:(?:plain)}/{endpoint:(?:mentions|users|tweets)}").