-
Notifications
You must be signed in to change notification settings - Fork 37
Open
Description
My gorilla mux routes are set up using controllers so that each route has access to the app's runtime, which contains important config variables.
The handlers on the controller have a similar signature as the ones provided in the repo's example by accepting http.ReponseWriter and *http.Request as arguments with no return value. The only difference is that it's registered as methods on the controller. Here's the whole setup:
// router.go
package main
r := mux.NewRouter()
r.KeepContext = true
r.StrictSlash(true)
orgsRouter := r.PathPrefix("/v3.1/orgs").Subrouter()
oc := orgs.NewOrgController(runtime)
orgsRouter.HandleFunc("", oc.CreateOrgHandler).Methods("POST").Name("CreateOrgHandler")
orgsRouter.HandleFunc("/{org_irv_id}", oc.GetOrgHandler).Methods("GET").Name("GetOrgsAndAccessForUserHandler")
orgsRouter.HandleFunc("/{org_irv_id}", oc.UpdateOrgHandler).Methods("PUT").Name("GetOrgHandler")
// controller.go
package orgs
type OrgController struct {
runtime *irv_core.IRV_runtime
}
func NewOrgController(runtime *irv_core.IRV_runtime) *OrgController {
return &OrgController{runtime}
}
// CreateOrgHandler creates an org
func (oc OrgController) CreateOrgHandler(w http.ResponseWriter, r *http.Request){
...
}
// GetOrgHandler gets an org by ID
func (oc OrgController) GetOrgHandler(w http.ResponseWriter, r *http.Request) {
...
}
// UpdateOrgHandler updates an org by ID
func (oc OrgController) UpdateOrgHandler(w http.ResponseWriter, r *http.Request) {
...
}Unfortunately the resulting .apib file looks unusual. None of the route names nor descriptions appear; instead, the raw URL is listed and all descriptions are labeled SERVE H T T P. Here's an excerpt:
...
## /v3.1/orgs/512df1c7-fef8-4e49-9f38-482f40534213
### Serve H T T P [GET]
...
## /v3.1/orgs/875a041d-57f2-4696-b596-a7ee3d9840e9
### Serve H T T P [PUT]
...
Please let me know if there's a possible fix here. Thanks!
Metadata
Metadata
Assignees
Labels
No labels