希望可以支持为Group设置中间件 #2

Closed
opened 2015-03-04 09:09:56 +00:00 by lunny · 3 comments
Owner

Author: @Shuenhoy

Author: @Shuenhoy
Author
Owner

Author: @lunny

其实只要在中间件中匹配Group的前缀就可以了。

Author: @lunny 其实只要在中间件中匹配Group的前缀就可以了。
Author
Owner

Author: @lunny

不知道有没有解决你的问题?@Shuenhoy

Author: @lunny 不知道有没有解决你的问题?@Shuenhoy
Author
Owner

Author: @lunny

Now, you can use the below code to add a middleware to a group. All the handlers could be add to group.

o := tango.Classic()
o.Group("/api", func(g *Group) {
        g.Use(HandlerFunc(func (ctx *Context) {
            fmt.Println("this is a group middleware")
            ctx.Next()
        }))
        g.Get("/1", func() string {
            return "/1"
        })
    })
Author: @lunny Now, you can use the below code to add a middleware to a group. All the handlers could be add to group. ``` o := tango.Classic() o.Group("/api", func(g *Group) { g.Use(HandlerFunc(func (ctx *Context) { fmt.Println("this is a group middleware") ctx.Next() })) g.Get("/1", func() string { return "/1" }) }) ```
Sign in to join this conversation.
No Milestone
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: lunny/tango#2
No description provided.