• 在 Golang 中,每个 Goroutine 创建的时候,我们要使用 defer 和 recover 关键字为当前 Goroutine 捕获 panic 异常,并进行处理,否则,任意一处 panic 就会导致整个进程崩溃!
func (engine *Engine) handleHTTPRequest(c *Context) {
	...
	// Find root of the tree for the given HTTP method
	t := engine.trees
	for i, tl := 0, len(t); i < tl; i++ {
		if t[i].method != httpMethod {
			continue
		}
		root := t[i].root
		// Find route in tree
		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
	}

...
}

文章作者: 永远的超神
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 永远的超神 !
  目录