代码拉取完成,页面将自动刷新
同步操作将从 lunny/tango 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
// Copyright 2015 The Tango Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package tango
type groupRouter struct {
methods interface{}
url string
c interface{}
handlers []Handler
}
// Group defines a route group
type Group struct {
routers []groupRouter
handlers []Handler
}
// NewGroup creates a route group
func NewGroup() *Group {
return &Group{
routers: make([]groupRouter, 0),
handlers: make([]Handler, 0),
}
}
// Use set the middlewares to apply to this group's routes
func (g *Group) Use(handlers ...Handler) {
g.handlers = append(g.handlers, handlers...)
}
// Get addes a GET route to this group
func (g *Group) Get(url string, c interface{}, middlewares ...Handler) {
g.Route([]string{"GET", "HEAD:Get"}, url, c, middlewares...)
}
// Post addes a POST route to this group
func (g *Group) Post(url string, c interface{}, middlewares ...Handler) {
g.Route([]string{"POST"}, url, c, middlewares...)
}
// Head addes a HEAD route to this group
func (g *Group) Head(url string, c interface{}, middlewares ...Handler) {
g.Route([]string{"HEAD"}, url, c, middlewares...)
}
// Options addes a OPTIONS route to this group
func (g *Group) Options(url string, c interface{}, middlewares ...Handler) {
g.Route([]string{"OPTIONS"}, url, c, middlewares...)
}
// Trace addes a TRACE route to this group
func (g *Group) Trace(url string, c interface{}, middlewares ...Handler) {
g.Route([]string{"TRACE"}, url, c, middlewares...)
}
// Patch addes a PATCH route to this group
func (g *Group) Patch(url string, c interface{}, middlewares ...Handler) {
g.Route([]string{"PATCH"}, url, c, middlewares...)
}
// Delete addes a DELETE route to this group
func (g *Group) Delete(url string, c interface{}, middlewares ...Handler) {
g.Route([]string{"DELETE"}, url, c, middlewares...)
}
// Put addes a PUT route to this group
func (g *Group) Put(url string, c interface{}, middlewares ...Handler) {
g.Route([]string{"PUT"}, url, c, middlewares...)
}
// Any addes the default mehtods route to this group
func (g *Group) Any(url string, c interface{}, middlewares ...Handler) {
g.Route(SupportMethods, url, c, middlewares...)
g.Route([]string{"HEAD:Get"}, url, c, middlewares...)
}
// Route defines a customerize route to this group
func (g *Group) Route(methods interface{}, url string, c interface{}, middlewares ...Handler) {
g.routers = append(g.routers, groupRouter{methods, url, c, middlewares})
}
// Group defines group's child group
func (g *Group) Group(p string, o interface{}, handlers ...Handler) {
gr := getGroup(o)
if len(handlers) > 0 {
gr.handlers = append(handlers, gr.handlers...)
}
for _, gchild := range gr.routers {
g.Route(gchild.methods, joinRoute(p, gchild.url), gchild.c, append(gr.handlers, gchild.handlers...)...)
}
}
func getGroup(o interface{}) *Group {
var g *Group
var gf func(*Group)
var ok bool
if g, ok = o.(*Group); ok {
} else if gf, ok = o.(func(*Group)); ok {
g = NewGroup()
gf(g)
} else {
panic("not allowed group parameter")
}
return g
}
func joinRoute(p, url string) string {
if len(p) == 0 || p == "/" {
return url
}
return p + url
}
func (t *Tango) addGroup(p string, g *Group) {
for _, r := range g.routers {
t.Route(r.methods, joinRoute(p, r.url), r.c, append(g.handlers, r.handlers...)...)
}
}
// Group adds routines groups
func (t *Tango) Group(p string, o interface{}, handlers ...Handler) {
g := getGroup(o)
g.handlers = append(handlers, g.handlers...)
t.addGroup(p, g)
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。