Skip to content
This repository has been archived by the owner on Feb 24, 2024. It is now read-only.

updated router Group function to acount for Windows path cruft #259

Merged
merged 5 commits into from
Feb 21, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions router.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"fmt"
"net/http"
"path"
"path/filepath"
"sort"
//"strings"

"github.com/markbates/inflect"
)
Expand Down Expand Up @@ -81,18 +81,18 @@ func (a *App) ServeFiles(p string, root http.FileSystem) {
g.DELETE("/{user_id}", ur.Destroy) DELETE /users/{user_id} => ur.Destroy
*/
func (a *App) Resource(p string, r Resource) *App {
base := filepath.Base(p)
base := path.Base(p)
single := inflect.Singularize(base)
g := a.Group(p)
p = "/"
spath := filepath.Join(p, fmt.Sprintf("{%s_id}", single))
spath := path.Join(p, fmt.Sprintf("{%s_id}", single))
g.GET(p, r.List)
g.GET(filepath.Join(p, "new"), r.New)
g.GET(filepath.Join(spath), r.Show)
g.GET(filepath.Join(spath, "edit"), r.Edit)
g.GET(path.Join(p, "new"), r.New)
g.GET(path.Join(spath), r.Show)
g.GET(path.Join(spath, "edit"), r.Edit)
g.POST(p, r.Create)
g.PUT(filepath.Join(spath), r.Update)
g.DELETE(filepath.Join(spath), r.Destroy)
g.PUT(path.Join(spath), r.Update)
g.DELETE(path.Join(spath), r.Destroy)
return g
}

Expand All @@ -117,9 +117,11 @@ func (a *App) ANY(p string, h Handler) {
g.GET("/users, APIUsersHandler)
g.GET("/users/:user_id, APIUserShowHandler)
*/
func (a *App) Group(path string) *App {
func (a *App) Group(groupPath string) *App {
g := New(a.Options)
g.prefix = filepath.Join(a.prefix, path)

g.prefix = path.Join(a.prefix, groupPath)

g.router = a.router
g.Middleware = a.Middleware.clone()
g.ErrorHandlers = a.ErrorHandlers
Expand All @@ -135,6 +137,7 @@ func (a *App) addRoute(method string, url string, h Handler) RouteInfo {
defer a.moot.Unlock()

url = path.Join(a.prefix, url)

hs := funcKey(h)
r := RouteInfo{
Method: method,
Expand Down