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:
parent
a02102d755
commit
f8c7330eb3
@ -180,9 +180,18 @@ indices: 子节点索引,当子节点为非参数类型,即本节点的 wild
|
||||
|
||||
由于 `:id` 这个节点只有一个字符串的普通子节点,所以 indices 还依然不需要处理。
|
||||
|
||||
上面这种情况比较简单,新的路由可以直接作为原路由的子节点进行插入。实际情况不会这么美好,接下来我们插入 `GET /search`,这时会导致树的边分裂。
|
||||
上面这种情况比较简单,新的路由可以直接作为原路由的子节点进行插入。实际情况不会这么美好。
|
||||
|
||||
### 边分裂
|
||||
接下来我们插入 `GET /search`,这时会导致树的边分裂。
|
||||
|
||||

|
||||
|
||||
原有路径和新的路径在初始的 `/` 位置发生分裂,这样需要把原有的 root 节点内容下移,再将新路由 `search` 同样作为子节点挂在 root 节点之下。这时候因为子节点出现多个,root 节点的 indices 提供子节点索引,这时候该字段就需要派上用场了。"ms" 代表子节点的首字母分别为 m(marketplace) 和 s(search)。
|
||||
|
||||
我们一口作气,把 `GET /status` 和 `GET /support` 也插入到树中。这时候会导致在 `search` 节点上再次发生分裂,来看看最终的结果:
|
||||
|
||||

|
||||
|
||||
### 子节点冲突处理
|
||||
|
||||
|
BIN
images/ch6-02-radix-get-3.png
Normal file
BIN
images/ch6-02-radix-get-3.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 86 KiB |
BIN
images/ch6-02-radix-get-4.png
Normal file
BIN
images/ch6-02-radix-get-4.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 97 KiB |
Loading…
x
Reference in New Issue
Block a user