diff options
author | Ben Morrison <ben@gbmor.dev> | 2019-05-20 00:53:07 -0400 |
---|---|---|
committer | Ben Morrison <ben@gbmor.dev> | 2019-05-20 02:12:08 -0400 |
commit | efa99ed5253c229c83d8f2d98ee1c08b4383184e (patch) | |
tree | 6c91f0436eff5e31d9be892b6d2f2adfbb3a030c /http.go | |
parent | 747f4fb70ff61d3f8a7bb1bed896a913b0999450 (diff) | |
download | getwtxt-efa99ed5253c229c83d8f2d98ee1c08b4383184e.tar.gz |
endpoint query function added
Diffstat (limited to 'http.go')
-rw-r--r-- | http.go | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/http.go b/http.go index 52f9923..b338796 100644 --- a/http.go +++ b/http.go @@ -108,15 +108,16 @@ func apiFormatHandler(w http.ResponseWriter, r *http.Request) { // handles "/api/plain/(users|mentions|tweets)" func apiEndpointHandler(w http.ResponseWriter, r *http.Request) { - vars := mux.Vars(r) - format := vars["format"] - endpoint := vars["endpoint"] - uip := getIPFromCtx(r.Context()) log.Printf("Request from %v :: %v %v\n", uip, r.Method, r.URL) + if r.FormValue("q") != "" || r.FormValue("url") != "" { + apiEndpointQuery(w, r) + return + } + w.Header().Set("Content-Type", htmlutf8) - n, err := w.Write([]byte(format + "/" + endpoint)) + n, err := w.Write([]byte(r.URL.String())) if err != nil || n == 0 { log.Printf("500: Error writing to HTTP stream: %v, %v %v via %v\n", err, r.Method, r.URL, uip) http.Error(w, err.Error(), http.StatusInternalServerError) |