MCPcopy
hub / github.com/gofiber/fiber / match

Method match

router.go:180–223  ·  view source on GitHub ↗
(detectionPath, path string, params *[maxParams]string)

Source from the content-addressed store, hash-verified

178}
179
180func (r *Route) match(detectionPath, path string, params *[maxParams]string) bool {
181 // root detectionPath check
182 if r.root && len(detectionPath) == 1 && detectionPath[0] == '/' {
183 return true
184 }
185
186 // '*' wildcard matches any detectionPath
187 if r.star {
188 if len(path) > 1 {
189 params[0] = path[1:]
190 } else {
191 params[0] = ""
192 }
193 return true
194 }
195
196 // Does this route have parameters?
197 if len(r.Params) > 0 {
198 // Match params using precomputed routeParser
199 return r.routeParser.getMatch(detectionPath, path, params, r.use)
200 }
201
202 // Middleware route?
203 if r.use {
204 // Single slash or prefix match
205 plen := len(r.path)
206 if r.root {
207 // If r.root is '/', it matches everything starting at '/'
208 if detectionPath != "" && detectionPath[0] == '/' {
209 return true
210 }
211 } else if len(detectionPath) >= plen && detectionPath[:plen] == r.path {
212 if hasPartialMatchBoundary(detectionPath, plen) {
213 return true
214 }
215 }
216 } else if len(r.path) == len(detectionPath) && detectionPath == r.path {
217 // Check exact match
218 return true
219 }
220
221 // No match
222 return false
223}
224
225func (app *App) next(c *DefaultCtx) (bool, error) {
226 methodInt := c.methodInt

Callers 11

Test_Route_Match_StarFunction · 0.95
Benchmark_Route_MatchFunction · 0.95
nextMethod · 0.45
nextCustomMethod · 0.45
Test_domainMatcher_matchFunction · 0.45
Benchmark_Domain_MatchFunction · 0.45

Calls 2

hasPartialMatchBoundaryFunction · 0.85
getMatchMethod · 0.80