diff options
author | Ben Morrison <ben@gbmor.dev> | 2019-05-11 03:32:00 -0400 |
---|---|---|
committer | Ben Morrison <ben@gbmor.dev> | 2019-05-11 03:32:00 -0400 |
commit | d4c05d21a4de2fe8f492957b66f40aa5e6757dca (patch) | |
tree | 620378cd1968cf31718c7ba1a03939f5411ac463 /handlers.go | |
parent | 474ffad421eee04a50cbdd5cfbc2b396c24dc521 (diff) | |
download | getwtxt-d4c05d21a4de2fe8f492957b66f40aa5e6757dca.tar.gz |
skeleton handlers responding
Diffstat (limited to 'handlers.go')
-rw-r--r-- | handlers.go | 42 |
1 files changed, 41 insertions, 1 deletions
diff --git a/handlers.go b/handlers.go index 4b2ceef..ac52559 100644 --- a/handlers.go +++ b/handlers.go @@ -6,6 +6,8 @@ import ( "log" "net/http" "time" + + "github.com/gorilla/mux" ) func apiBaseHandler(w http.ResponseWriter, r *http.Request) { @@ -15,7 +17,7 @@ func apiBaseHandler(w http.ResponseWriter, r *http.Request) { } etag := fmt.Sprintf("%x", sha256.Sum256(timerfc3339)) w.Header().Set("ETag", etag) - w.Header().Set("Content-Type", textutf8) + w.Header().Set("Content-Type", txtutf8) pathdata := []byte("\n\n" + r.URL.Path) timerfc3339 = append(timerfc3339, pathdata...) n, err := w.Write(timerfc3339) @@ -25,17 +27,55 @@ func apiBaseHandler(w http.ResponseWriter, r *http.Request) { } func indexHandler(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", htmlutf8) + n, err := w.Write([]byte(getwtxt)) + if err != nil || n == 0 { + log.Printf("Error writing to HTTP stream: %v\n", err) + } } func apiFormatHandler(w http.ResponseWriter, r *http.Request) { + vars := mux.Vars(r) + format := vars["format"] + w.Header().Set("Content-Type", txtutf8) + n, err := w.Write([]byte(format + "\n")) + if err != nil || n == 0 { + log.Printf("Error writing to HTTP stream: %v\n", err) + } } func apiEndpointHandler(w http.ResponseWriter, r *http.Request) { + vars := mux.Vars(r) + format := vars["format"] + endpoint := vars["endpoint"] + + w.Header().Set("Content-Type", htmlutf8) + n, err := w.Write([]byte(format + "/" + endpoint)) + if err != nil || n == 0 { + log.Printf("Error writing to HTTP stream: %v\n", err) + } } func apiTagsBaseHandler(w http.ResponseWriter, r *http.Request) { + vars := mux.Vars(r) + format := vars["format"] + + w.Header().Set("Content-Type", htmlutf8) + n, err := w.Write([]byte("api/" + format + "/tags")) + if err != nil || n == 0 { + log.Printf("Error writing to HTTP stream: %v\n", err) + } } func apiTagsHandler(w http.ResponseWriter, r *http.Request) { + vars := mux.Vars(r) + format := vars["format"] + tags := vars["tags"] + + w.Header().Set("Content-Type", htmlutf8) + n, err := w.Write([]byte("api/" + format + "/" + tags)) + if err != nil || n == 0 { + log.Printf("Error writing to HTTP stream: %v\n", err) + } } |