- 在 Golang 中,每个 Goroutine 创建的时候,我们要使用 defer 和 recover 关键字为当前 Goroutine 捕获 panic 异常,并进行处理,否则,任意一处 panic 就会导致整个进程崩溃!
func (engine *Engine) handleHTTPRequest(c *Context) {
...
t := engine.trees
for i, tl := 0, len(t); i < tl; i++ {
if t[i].method != httpMethod {
continue
}
root := t[i].root
value := root.getValue(rPath, c.params, c.skippedNodes, unescape)
if value.params != nil {
c.Params = *value.params
}
if value.handlers != nil {
c.handlers = value.handlers
c.fullPath = value.fullPath
c.Next()
c.writermem.WriteHeaderNow()
return
}
...
}
break
}
...
}