From b9d16fbfcc9032518cd464060276755a8d09caf4 Mon Sep 17 00:00:00 2001 From: Ben Morrison Date: Sat, 11 May 2019 03:04:28 -0400 Subject: stubbed out handlers --- go.mod | 5 ----- go.sum | 2 -- handlers.go | 30 +++++++++++++++++------------- main.go | 10 ++++++++-- 4 files changed, 25 insertions(+), 22 deletions(-) delete mode 100644 go.mod delete mode 100644 go.sum diff --git a/go.mod b/go.mod deleted file mode 100644 index 5da3388..0000000 --- a/go.mod +++ /dev/null @@ -1,5 +0,0 @@ -module github.com/gbmor/getwtxt - -go 1.11 - -require github.com/gorilla/handlers v1.4.0 diff --git a/go.sum b/go.sum deleted file mode 100644 index d4945cc..0000000 --- a/go.sum +++ /dev/null @@ -1,2 +0,0 @@ -github.com/gorilla/handlers v1.4.0 h1:XulKRWSQK5uChr4pEgSE4Tc/OcmnU9GJuSwdog/tZsA= -github.com/gorilla/handlers v1.4.0/go.mod h1:Qkdc/uu4tH4g6mTK6auzZ766c4CA0Ng8+o/OAirnOIQ= diff --git a/handlers.go b/handlers.go index d57feee..4b2ceef 100644 --- a/handlers.go +++ b/handlers.go @@ -8,19 +8,7 @@ import ( "time" ) -func validRequest(fn func(http.ResponseWriter, *http.Request, string)) http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { - m := confObj.validPath.FindStringSubmatch(r.URL.Path) - if m == nil { - log.Printf("Invalid API request: %v", r.URL.Path) - http.Error(w, fmt.Errorf(r.URL.Path).Error(), http.StatusNotFound) - return - } - fn(w, r, m[2]) - } -} - -func apiHandler(w http.ResponseWriter, r *http.Request) { +func apiBaseHandler(w http.ResponseWriter, r *http.Request) { timerfc3339, err := time.Now().MarshalText() if err != nil { log.Printf("Couldn't format time as RFC3339: %v\n", err) @@ -35,3 +23,19 @@ func apiHandler(w http.ResponseWriter, r *http.Request) { log.Printf("Error writing to HTTP stream: %v\n", err) } } + +func indexHandler(w http.ResponseWriter, r *http.Request) { + +} +func apiFormatHandler(w http.ResponseWriter, r *http.Request) { + +} +func apiEndpointHandler(w http.ResponseWriter, r *http.Request) { + +} +func apiTagsBaseHandler(w http.ResponseWriter, r *http.Request) { + +} +func apiTagsHandler(w http.ResponseWriter, r *http.Request) { + +} diff --git a/main.go b/main.go index 374b94f..06d124a 100644 --- a/main.go +++ b/main.go @@ -5,14 +5,20 @@ import ( "net/http" "github.com/gorilla/handlers" + "github.com/gorilla/mux" ) func main() { log.Printf("getwtxt v0.1\n") - serv := http.NewServeMux() + serv := mux.NewRouter() - serv.HandleFunc("/api/", apiHandler) + serv.HandleFunc("/", indexHandler) + serv.HandleFunc("/api/", apiBaseHandler) + serv.HandleFunc("/api/{format:plain}", apiFormatHandler) + serv.HandleFunc("/api/{format:plain}/{endpoint:mentions|users|tweets}", apiEndpointHandler) + serv.HandleFunc("/api/{format:plain}/tags/{tags:[a-zA-Z0-9]+}", apiTagsHandler) + serv.HandleFunc("/api/{format:plain}/tags", apiTagsBaseHandler) log.Fatalln(http.ListenAndServe(":8080", handlers.CompressHandler(serv))) } -- cgit 1.4.1-2-gfad0