diff options
author | Ben Morrison <ben@gbmor.dev> | 2019-05-12 23:36:04 -0400 |
---|---|---|
committer | Ben Morrison <ben@gbmor.dev> | 2019-05-12 23:36:04 -0400 |
commit | d2680fb62bac6c779f371b2b6839592274a8d281 (patch) | |
tree | ae6adcc3609396a44eed63462e292c57066f1dcb /main.go | |
parent | 1f8b2ce166e104bca99e4a758bb658dd27d5e4d6 (diff) | |
download | getwtxt-d2680fb62bac6c779f371b2b6839592274a8d281.tar.gz |
reorganized handlers. StrictSlash(true). handling POST /api/plain/users for new users
Diffstat (limited to 'main.go')
-rw-r--r-- | main.go | 34 |
1 files changed, 25 insertions, 9 deletions
diff --git a/main.go b/main.go index ef083dc..267c4ea 100644 --- a/main.go +++ b/main.go @@ -14,20 +14,36 @@ const getwtxt = "0.1" func main() { - // more precise path-based routing - index := mux.NewRouter() + index := mux.NewRouter().StrictSlash(true) api := index.PathPrefix("/api").Subrouter() // gorilla/mux makes path validation painless - index.HandleFunc("/", indexHandler) - index.HandleFunc("/api", apiBaseHandler) - api.HandleFunc("/", apiBaseHandler) - api.HandleFunc("/{format:(?:plain)}", apiFormatHandler) + index.Path("/"). + Methods("GET"). + HandlerFunc(indexHandler) + index.Path("/api"). + Methods("GET"). + HandlerFunc(apiBaseHandler) + api.Path("/"). + Methods("GET"). + HandlerFunc(apiBaseHandler) + api.Path("/{format:(?:plain)}"). + Methods("GET"). + HandlerFunc(apiFormatHandler) api.Path("/{format:(?:plain)}/{endpoint:(?:mentions|users|tweets)}"). - Queries("url", "{url}", "q", "{query}", "nickname", "{nickname}"). + Methods("GET"). + Queries("url", "{url}", "q", "{query}"). HandlerFunc(apiEndpointHandler) - api.HandleFunc("/{format:(?:plain)}/tags", apiTagsBaseHandler) - api.HandleFunc("/{format:(?:plain)}/tags/{tags:[a-zA-Z0-9]+}", apiTagsHandler) + api.Path("/{format:(?:plain)}/{endpoint:users}"). + Methods("POST"). + Queries("url", "{url}", "nickname", "{nickname}"). + HandlerFunc(apiEndpointPOSTHandler) + api.Path("/{format:(?:plain)}/tags"). + Methods("GET"). + HandlerFunc(apiTagsBaseHandler) + api.Path("/{format:(?:plain)}/tags/{tags:[a-zA-Z0-9]+}"). + Methods("GET"). + HandlerFunc(apiTagsHandler) // format the port for the http.Server object portnum := fmt.Sprintf(":%v", confObj.port) |