Skip to content

Commit

Permalink
api: split keyCombined args in gorilla/mux
Browse files Browse the repository at this point in the history
We need two routes, as we support either one or two arguments.
  • Loading branch information
mvdan authored and buger committed Jul 7, 2017
1 parent f212ba8 commit 3523717
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 19 deletions.
21 changes: 3 additions & 18 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -1163,26 +1163,11 @@ func invalidateOauthRefresh(w http.ResponseWriter, r *http.Request) {
}

func oAuthClientHandler(w http.ResponseWriter, r *http.Request) {
// TODO: split these two args in the router
keyCombined := mux.Vars(r)["keyCombined"]
apiID := mux.Vars(r)["apiID"]
keyName := mux.Vars(r)["keyName"]

var obj interface{}
var code int

keyName := ""
apiID := ""

parts := strings.Split(keyCombined, "/")
switch len(parts) {
case 2:
keyName = parts[1]
apiID = parts[0]
case 1:
apiID = parts[0]
default:
doJSONWrite(w, 400, apiError("Missing URL params"))
return
}

switch r.Method {
case "GET":
if keyName != "" {
Expand Down
3 changes: 2 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,8 @@ func loadAPIEndpoints(muxer *mux.Router) {
}

r.HandleFunc("/keys/{keyName}", allowMethods(keyHandler, "POST", "PUT", "GET", "DELETE"))
r.HandleFunc("/oauth/clients/{keyCombined:.*}", allowMethods(oAuthClientHandler, "GET", "DELETE"))
r.HandleFunc("/oauth/clients/{apiID}", allowMethods(oAuthClientHandler, "GET", "DELETE"))
r.HandleFunc("/oauth/clients/{apiID}/{keyName}", allowMethods(oAuthClientHandler, "GET", "DELETE"))

log.WithFields(logrus.Fields{
"prefix": "main",
Expand Down

0 comments on commit 3523717

Please sign in to comment.