mirror of https://github.com/gin-gonic/gin.git
parent
ee7c6d03b7
commit
bb8194b526
26
gin.go
26
gin.go
|
@ -147,6 +147,9 @@ type Engine struct {
|
||||||
// UseH2C enable h2c support.
|
// UseH2C enable h2c support.
|
||||||
UseH2C bool
|
UseH2C bool
|
||||||
|
|
||||||
|
// ContextWithFallback enable fallback Context.Deadline(), Context.Done(), Context.Err() and Context.Value() when Context.Request.Context() is not nil.
|
||||||
|
ContextWithFallback bool
|
||||||
|
|
||||||
delims render.Delims
|
delims render.Delims
|
||||||
secureJSONPrefix string
|
secureJSONPrefix string
|
||||||
HTMLRender render.HTMLRender
|
HTMLRender render.HTMLRender
|
||||||
|
@ -195,7 +198,7 @@ func New() *Engine {
|
||||||
trees: make(methodTrees, 0, 9),
|
trees: make(methodTrees, 0, 9),
|
||||||
delims: render.Delims{Left: "{{", Right: "}}"},
|
delims: render.Delims{Left: "{{", Right: "}}"},
|
||||||
secureJSONPrefix: "while(1);",
|
secureJSONPrefix: "while(1);",
|
||||||
trustedProxies: []string{"0.0.0.0/0"},
|
trustedProxies: []string{"0.0.0.0/0", "::/0"},
|
||||||
trustedCIDRs: defaultTrustedCIDRs,
|
trustedCIDRs: defaultTrustedCIDRs,
|
||||||
}
|
}
|
||||||
engine.RouterGroup.engine = engine
|
engine.RouterGroup.engine = engine
|
||||||
|
@ -207,6 +210,7 @@ func New() *Engine {
|
||||||
|
|
||||||
// Default returns an Engine instance with the Logger and Recovery middleware already attached.
|
// Default returns an Engine instance with the Logger and Recovery middleware already attached.
|
||||||
func Default() *Engine {
|
func Default() *Engine {
|
||||||
|
println("hello hsy")
|
||||||
debugPrintWARNINGDefault()
|
debugPrintWARNINGDefault()
|
||||||
engine := New()
|
engine := New()
|
||||||
engine.Use(Logger(), Recovery())
|
engine.Use(Logger(), Recovery())
|
||||||
|
@ -337,7 +341,6 @@ func (engine *Engine) addRoute(method, path string, handlers HandlersChain) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func (engine *Engine) delRoute(method, path string) {
|
func (engine *Engine) delRoute(method, path string) {
|
||||||
assert1(path[0] == '/', "path must begin with '/'")
|
assert1(path[0] == '/', "path must begin with '/'")
|
||||||
assert1(method != "", "HTTP method can not be empty")
|
assert1(method != "", "HTTP method can not be empty")
|
||||||
|
@ -355,15 +358,6 @@ func (engine *Engine) delRoute(method, path string) {
|
||||||
}else {
|
}else {
|
||||||
root.delChildNode(target)
|
root.delChildNode(target)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update maxParams
|
|
||||||
if paramsCount := countParams(path); paramsCount == engine.maxParams {
|
|
||||||
//TODO:find new maxParams
|
|
||||||
}
|
|
||||||
|
|
||||||
if sectionsCount := countSections(path); sectionsCount == engine.maxSections {
|
|
||||||
//TODO:find new maxParams
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *node) findNode(path string) (target *node,parent *node,found bool,myself bool){
|
func (n *node) findNode(path string) (target *node,parent *node,found bool,myself bool){
|
||||||
|
@ -390,7 +384,7 @@ func (n *node) delChildNode(target *node){
|
||||||
if target.path[0] == n.indices[i] {
|
if target.path[0] == n.indices[i] {
|
||||||
n.indices = n.indices[:i] + n.indices[i+1:]
|
n.indices = n.indices[:i] + n.indices[i+1:]
|
||||||
n.children = append(n.children[:i], n.children[i+1:]...)
|
n.children = append(n.children[:i], n.children[i+1:]...)
|
||||||
//TODO:update other params of n
|
n.priority --
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -399,20 +393,16 @@ func (n *node) delChildNode(target *node){
|
||||||
if target.path[0] == n.indices[i] {
|
if target.path[0] == n.indices[i] {
|
||||||
n.indices = n.indices[:i] + string(target.children[0].path[0]) + n.indices[i+1:]
|
n.indices = n.indices[:i] + string(target.children[0].path[0]) + n.indices[i+1:]
|
||||||
n.children[i] = target.children[0]
|
n.children[i] = target.children[0]
|
||||||
//TODO:update other params of n
|
n.priority --
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
target.handlers = nil
|
target.handlers = nil
|
||||||
//TODO:update other params of target
|
|
||||||
}
|
}
|
||||||
if len(n.children) == 1 {
|
|
||||||
//TODO:combine n and n.children[0]
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Routes returns a slice of registered routes, including some useful information, such as:
|
// Routes returns a slice of registered routes, including some useful information, such as:
|
||||||
// the http method, path and the handler name.
|
// the http method, path and the handler name.
|
||||||
func (engine *Engine) Routes() (routes RoutesInfo) {
|
func (engine *Engine) Routes() (routes RoutesInfo) {
|
||||||
|
|
Loading…
Reference in New Issue