forked from Fuyu/router
Clean paths in Group
This commit is contained in:
parent
ae68248d25
commit
5a44e82541
20
group.go
20
group.go
@ -2,48 +2,52 @@ package router
|
||||
|
||||
import urlpath "path"
|
||||
|
||||
func join(prefix, path string) string {
|
||||
return urlpath.Join(prefix, urlpath.Clean(path))
|
||||
}
|
||||
|
||||
type Group struct {
|
||||
router *Router
|
||||
prefix string
|
||||
}
|
||||
|
||||
func (g *Group) Group(prefix string) *Group {
|
||||
return &Group{prefix: urlpath.Join(g.prefix, prefix), router: g.router}
|
||||
return &Group{prefix: join(g.prefix, prefix), router: g.router}
|
||||
}
|
||||
|
||||
// GET adds a GET route
|
||||
func (g *Group) GET(path string, handle GetHandle) {
|
||||
g.router.GET(urlpath.Join(g.prefix, path), handle)
|
||||
g.router.GET(join(g.prefix, path), handle)
|
||||
}
|
||||
|
||||
// POST adds a POST route
|
||||
func (g *Group) POST(path string, handle interface{}) {
|
||||
g.router.POST(urlpath.Join(g.prefix, path), handle)
|
||||
g.router.POST(join(g.prefix, path), handle)
|
||||
}
|
||||
|
||||
// DELETE adds a DELETE route
|
||||
func (g *Group) DELETE(path string, handle GetHandle) {
|
||||
g.router.DELETE(urlpath.Join(g.prefix, path), handle)
|
||||
g.router.DELETE(join(g.prefix, path), handle)
|
||||
}
|
||||
|
||||
// PUT adds a PUT route
|
||||
func (g *Group) PUT(path string, handle interface{}) {
|
||||
checkInterfaceHandle(handle)
|
||||
g.router.PUT(urlpath.Join(g.prefix, path), handle)
|
||||
g.router.PUT(join(g.prefix, path), handle)
|
||||
}
|
||||
|
||||
// PATCH adds a PATCH route
|
||||
func (g *Group) PATCH(path string, handle interface{}) {
|
||||
checkInterfaceHandle(handle)
|
||||
g.router.PATCH(urlpath.Join(g.prefix, path), handle)
|
||||
g.router.PATCH(join(g.prefix, path), handle)
|
||||
}
|
||||
|
||||
// HEAD adds a HEAD route
|
||||
func (g *Group) HEAD(path string, handle GetHandle) {
|
||||
g.router.HEAD(urlpath.Join(g.prefix, path), handle)
|
||||
g.router.HEAD(join(g.prefix, path), handle)
|
||||
}
|
||||
|
||||
// OPTIONS adds a OPTIONS route
|
||||
func (g *Group) OPTIONS(path string, handle GetHandle) {
|
||||
g.router.OPTIONS(urlpath.Join(g.prefix, path), handle)
|
||||
g.router.OPTIONS(join(g.prefix, path), handle)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user