From 10f3da09547af448d74a9c6f2948fe99aff23136 Mon Sep 17 00:00:00 2001 From: xfy Date: Mon, 20 Apr 2026 11:23:03 +0800 Subject: [PATCH] =?UTF-8?q?docs(matcher):=20=E4=B8=BA=20location=20?= =?UTF-8?q?=E5=8C=B9=E9=85=8D=E5=BC=95=E6=93=8E=E6=B7=BB=E5=8A=A0=E6=A0=87?= =?UTF-8?q?=E5=87=86=E5=8C=96=20godoc=20=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 4.7 --- internal/matcher/location.go | 16 ++++++++-------- internal/matcher/matcher.go | 5 +++-- internal/matcher/radix.go | 4 ++-- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/internal/matcher/location.go b/internal/matcher/location.go index 5ef547c..8207f30 100644 --- a/internal/matcher/location.go +++ b/internal/matcher/location.go @@ -4,10 +4,10 @@ // 按照 nginx 优先级顺序执行匹配。 // // 匹配优先级从高到低: -// 1. 精确匹配(=) -// 2. 前缀优先匹配(^~) -// 3. 正则匹配(~, ~*) -// 4. 普通前缀匹配 +// 1. 精确匹配(=) +// 2. 前缀优先匹配(^~) +// 3. 正则匹配(~, ~*) +// 4. 普通前缀匹配 // // 作者:xfy package matcher @@ -181,10 +181,10 @@ func (e *LocationEngine) AddNamed(name string, handler fasthttp.RequestHandler) // Match 统一匹配入口。 // // 按照 nginx 优先级顺序执行匹配: -// 1. 精确匹配(=)- O(1) -// 2. 前缀优先匹配(^~)- O(log n) -// 3. 正则匹配(~, ~*)- 按顺序 -// 4. 普通前缀匹配 - O(log n) +// 1. 精确匹配(=)- O(1) +// 2. 前缀优先匹配(^~)- O(log n) +// 3. 正则匹配(~, ~*)- 按顺序 +// 4. 普通前缀匹配 - O(log n) // // 参数: // - path: 请求路径 diff --git a/internal/matcher/matcher.go b/internal/matcher/matcher.go index 755d547..a300cdb 100644 --- a/internal/matcher/matcher.go +++ b/internal/matcher/matcher.go @@ -8,8 +8,9 @@ // - 命名匹配(named):@name 形式的内部跳转目标 // // 主要用途: -// 用于反向代理模块根据请求路径选择对应的后端处理器, -// 优先级顺序与 nginx 一致:精确 > 前缀优先(^~) > 正则(~,~*) > 普通前缀 +// +// 用于反向代理模块根据请求路径选择对应的后端处理器, +// 优先级顺序与 nginx 一致:精确 > 前缀优先(^~) > 正则(~,~*) > 普通前缀 // // 注意事项: // - Radix Tree 在初始化完成后不可修改(MarkInitialized 后 Insert 返回错误) diff --git a/internal/matcher/radix.go b/internal/matcher/radix.go index 5eeb456..a12cff1 100644 --- a/internal/matcher/radix.go +++ b/internal/matcher/radix.go @@ -214,8 +214,8 @@ func (t *RadixTree) FindLongestPrefix(path string) *MatchResult { // searchLongest 递归搜索最长前缀匹配。 // // 匹配规则: -// 1. 优先级数值越小越优先 -// 2. 相同优先级时,前缀越长越优先 +// 1. 优先级数值越小越优先 +// 2. 相同优先级时,前缀越长越优先 // // 参数: // - node: 当前搜索节点