1
0
mirror of https://github.com/chai2010/advanced-go-programming-book.git synced 2025-05-24 04:22:22 +00:00

update router

This commit is contained in:
Xargin 2018-01-07 17:02:05 +08:00
parent a02102d755
commit f8c7330eb3
3 changed files with 10 additions and 1 deletions

View File

@ -180,9 +180,18 @@ indices: 子节点索引,当子节点为非参数类型,即本节点的 wild
由于 `:id` 这个节点只有一个字符串的普通子节点,所以 indices 还依然不需要处理。 由于 `:id` 这个节点只有一个字符串的普通子节点,所以 indices 还依然不需要处理。
上面这种情况比较简单,新的路由可以直接作为原路由的子节点进行插入。实际情况不会这么美好,接下来我们插入 `GET /search`,这时会导致树的边分裂 上面这种情况比较简单,新的路由可以直接作为原路由的子节点进行插入。实际情况不会这么美好。
### 边分裂 ### 边分裂
接下来我们插入 `GET /search`,这时会导致树的边分裂。
![get radix step 3](../images/ch6-02-radix-get-3.png)
原有路径和新的路径在初始的 `/` 位置发生分裂,这样需要把原有的 root 节点内容下移,再将新路由 `search` 同样作为子节点挂在 root 节点之下。这时候因为子节点出现多个root 节点的 indices 提供子节点索引,这时候该字段就需要派上用场了。"ms" 代表子节点的首字母分别为 m(marketplace) 和 s(search)。
我们一口作气,把 `GET /status``GET /support` 也插入到树中。这时候会导致在 `search` 节点上再次发生分裂,来看看最终的结果:
![get radix step 4](../images/ch6-02-radix-get-4.png)
### 子节点冲突处理 ### 子节点冲突处理

Binary file not shown.

After

Width:  |  Height:  |  Size: 86 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 97 KiB