fix(routing): fix wildcard host suffix matching and PathRegexp error message

- Fix Host(".example.com") incorrectly matching bare "example.com" by
  using HasSuffix(reqHost, host) instead of HasSuffix(reqHost, host[1:])
- Fix PathRegexp matcher error message saying "PathPrefix" instead of
  "PathRegexp"
- Add doc comments to NewMatcher and Tree types
- Add 28 unit tests covering all matcher types, boolean operators,
  edge cases, and parameter validation
This commit is contained in:
ginuerzh
2026-05-25 23:03:53 +08:00
parent 4443b0b964
commit b7a4cb0251
3 changed files with 663 additions and 3 deletions
+4 -1
View File
@@ -14,12 +14,15 @@ const (
or = "or"
)
// Parser is an alias for the predicate parser used to parse routing rules.
type Parser = predicate.Parser
// TreeBuilder defines the type for a Tree builder.
type TreeBuilder func() *Tree
// Tree represents the rules' tree structure.
// Tree represents the rules' tree structure used for routing matchers.
// Leaf nodes hold a Matcher name, optional negation, and string values.
// Internal nodes hold an "and"/"or" operator with left and right children.
type Tree struct {
Matcher string
Not bool