[TOC]
综述
todo… not good
gin 框架的路由,本质上是一个前缀树。每一种http method有一颗数,并且前缀树采用最长前缀来表示, 而不是简单的通过斜杠分隔。
注册
获取树的根节点
1 | // 注意这里使用的是数组,在数据量很小的时候, 遍历数组肯定是比使用哈希表更高效的方式,由于http method 的方法就只有有限的几种类型,所以数组时更高效的选择。 |
tree node
1 | type node struct { |
nType 有这几个值
1 | const ( |
注册
…
处理请求
ServeHTTP
1 | func (engine *Engine) ServeHTTP(w http.ResponseWriter, req *http.Request) { |
寻找路由并处理动态参数
1 | // getValue returns the handle registered with the given path (key). The values of |