diff options
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) + } } |