...
1
17
18 package xdsresource
19
20 import (
21 "regexp"
22 "strings"
23
24 "google.golang.org/grpc/internal/grpcutil"
25 )
26
27 type pathMatcher interface {
28 match(path string) bool
29 String() string
30 }
31
32 type pathExactMatcher struct {
33
34 fullPath string
35 caseInsensitive bool
36 }
37
38 func newPathExactMatcher(p string, caseInsensitive bool) *pathExactMatcher {
39 ret := &pathExactMatcher{
40 fullPath: p,
41 caseInsensitive: caseInsensitive,
42 }
43 if caseInsensitive {
44 ret.fullPath = strings.ToUpper(p)
45 }
46 return ret
47 }
48
49 func (pem *pathExactMatcher) match(path string) bool {
50 if pem.caseInsensitive {
51 return pem.fullPath == strings.ToUpper(path)
52 }
53 return pem.fullPath == path
54 }
55
56 func (pem *pathExactMatcher) String() string {
57 return "pathExact:" + pem.fullPath
58 }
59
60 type pathPrefixMatcher struct {
61
62 prefix string
63 caseInsensitive bool
64 }
65
66 func newPathPrefixMatcher(p string, caseInsensitive bool) *pathPrefixMatcher {
67 ret := &pathPrefixMatcher{
68 prefix: p,
69 caseInsensitive: caseInsensitive,
70 }
71 if caseInsensitive {
72 ret.prefix = strings.ToUpper(p)
73 }
74 return ret
75 }
76
77 func (ppm *pathPrefixMatcher) match(path string) bool {
78 if ppm.caseInsensitive {
79 return strings.HasPrefix(strings.ToUpper(path), ppm.prefix)
80 }
81 return strings.HasPrefix(path, ppm.prefix)
82 }
83
84 func (ppm *pathPrefixMatcher) String() string {
85 return "pathPrefix:" + ppm.prefix
86 }
87
88 type pathRegexMatcher struct {
89 re *regexp.Regexp
90 }
91
92 func newPathRegexMatcher(re *regexp.Regexp) *pathRegexMatcher {
93 return &pathRegexMatcher{re: re}
94 }
95
96 func (prm *pathRegexMatcher) match(path string) bool {
97 return grpcutil.FullMatchWithRegex(prm.re, path)
98 }
99
100 func (prm *pathRegexMatcher) String() string {
101 return "pathRegex:" + prm.re.String()
102 }
103
View as plain text