Make Group return IRouter

This commit is contained in:
will@newrelic.com 2016-10-23 14:18:04 -07:00
parent c65e5efc9a
commit 7db833d1f4
3 changed files with 7 additions and 7 deletions

View File

@ -49,7 +49,7 @@ func NoMethod(handlers ...gin.HandlerFunc) {
// Group creates a new router group. You should add all the routes that have common middlwares or the same path prefix.
// For example, all the routes that use a common middlware for authorization could be grouped.
func Group(relativePath string, handlers ...gin.HandlerFunc) *gin.RouterGroup {
func Group(relativePath string, handlers ...gin.HandlerFunc) gin.IRouter {
return engine().Group(relativePath, handlers...)
}

View File

@ -14,7 +14,7 @@ import (
// IRouter defines all router handle interface includes single and group router.
type IRouter interface {
IRoutes
Group(string, ...HandlerFunc) *RouterGroup
Group(string, ...HandlerFunc) IRouter
}
// IRoutes defines all router handle interface.
@ -55,7 +55,7 @@ func (group *RouterGroup) Use(middleware ...HandlerFunc) IRoutes {
// Group creates a new router group. You should add all the routes that have common middlwares or the same path prefix.
// For example, all the routes that use a common middlware for authorization could be grouped.
func (group *RouterGroup) Group(relativePath string, handlers ...HandlerFunc) *RouterGroup {
func (group *RouterGroup) Group(relativePath string, handlers ...HandlerFunc) IRouter {
return &RouterGroup{
Handlers: group.combineHandlers(handlers),
basePath: group.calculateAbsolutePath(relativePath),

View File

@ -17,14 +17,14 @@ func init() {
func TestRouterGroupBasic(t *testing.T) {
router := New()
group := router.Group("/hola", func(c *Context) {})
group := router.Group("/hola", func(c *Context) {}).(*RouterGroup)
group.Use(func(c *Context) {})
assert.Len(t, group.Handlers, 2)
assert.Equal(t, "/hola", group.BasePath())
assert.Equal(t, router, group.engine)
group2 := group.Group("manu")
group2 := group.Group("manu").(*RouterGroup)
group2.Use(func(c *Context) {}, func(c *Context) {})
assert.Len(t, group2.Handlers, 4)
@ -44,10 +44,10 @@ func TestRouterGroupBasicHandle(t *testing.T) {
func performRequestInGroup(t *testing.T, method string) {
router := New()
v1 := router.Group("v1", func(c *Context) {})
v1 := router.Group("v1", func(c *Context) {}).(*RouterGroup)
assert.Equal(t, "/v1", v1.BasePath())
login := v1.Group("/login/", func(c *Context) {}, func(c *Context) {})
login := v1.Group("/login/", func(c *Context) {}, func(c *Context) {}).(*RouterGroup)
assert.Equal(t, "/v1/login/", login.BasePath())
handler := func(c *Context) {