refactor(router): add trailing slash to all endpoints
This commit is contained in:
@@ -17,7 +17,7 @@ func (router *router) projects(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
switch getMethod(r) {
|
||||
case http.MethodGet, http.MethodHead:
|
||||
if id := r.PathValue("id"); id != "" {
|
||||
if id := r.PathValue("ID"); id != "" {
|
||||
router.getProject(w, r)
|
||||
} else {
|
||||
router.listProjects(w, r)
|
||||
@@ -27,11 +27,11 @@ func (router *router) projects(w http.ResponseWriter, r *http.Request) {
|
||||
router.createProject(w, r)
|
||||
|
||||
case http.MethodDelete:
|
||||
if id := r.PathValue("id"); id != "" {
|
||||
if id := r.PathValue("ID"); id != "" {
|
||||
router.deleteProject(w, r)
|
||||
} else {
|
||||
exception.
|
||||
BadRequest(errors.New(`missing "id" path value`)).
|
||||
BadRequest(errors.New(`missing "ID" path value`)).
|
||||
ServeHTTP(w, r)
|
||||
}
|
||||
|
||||
@@ -81,10 +81,10 @@ func (router *router) getProject(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
id := r.PathValue("id")
|
||||
id := r.PathValue("ID")
|
||||
if id == "" {
|
||||
exception.
|
||||
BadRequest(fmt.Errorf(`a valid path value of "id" must be provided`)).
|
||||
BadRequest(fmt.Errorf(`a valid path value of "ID" must be provided`)).
|
||||
ServeHTTP(w, r)
|
||||
return
|
||||
}
|
||||
@@ -154,10 +154,10 @@ func (router *router) deleteProject(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
id := r.PathValue("id")
|
||||
id := r.PathValue("ID")
|
||||
if id == "" {
|
||||
exception.
|
||||
BadRequest(fmt.Errorf(`a valid path value of "id" must be provided`)).
|
||||
BadRequest(fmt.Errorf(`a valid path value of "ID" must be provided`)).
|
||||
ServeHTTP(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -91,11 +91,12 @@ func (router *router) setup() http.Handler {
|
||||
r.Use(exception.PanicMiddleware())
|
||||
r.Use(exception.Middleware())
|
||||
|
||||
r.Handle("/assets", http.StripPrefix("/assets/", http.FileServerFS(router.assets)))
|
||||
r.Handle("/assets/", http.StripPrefix("/assets/", http.FileServerFS(router.assets)))
|
||||
|
||||
r.HandleFunc("/dashboard", router.dashboard)
|
||||
r.HandleFunc("/dashboard/", router.dashboard)
|
||||
|
||||
r.HandleFunc("/projects/{id...}", router.projects)
|
||||
r.HandleFunc("/projects/{$}", router.projects)
|
||||
r.HandleFunc("/projects/{ID}/", router.projects)
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user