MCPcopy
hub / github.com/gin-gonic/gin / findWildcard

Function findWildcard

tree.go:253–286  ·  view source on GitHub ↗

Search for a wildcard segment and check the name for invalid characters. Returns -1 as index, if no wildcard was found.

(path string)

Source from the content-addressed store, hash-verified

251// Search for a wildcard segment and check the name for invalid characters.
252// Returns -1 as index, if no wildcard was found.
253func findWildcard(path string) (wildcard string, i int, valid bool) {
254 // Find start
255 escapeColon := false
256 for start, c := range []byte(path) {
257 if escapeColon {
258 escapeColon = false
259 if c == ':' {
260 continue
261 }
262 panic("invalid escape string in path '" + path + "'")
263 }
264 if c == '\\' {
265 escapeColon = true
266 continue
267 }
268 // A wildcard starts with ':' (param) or '*' (catch-all)
269 if c != ':' && c != '*' {
270 continue
271 }
272
273 // Find end and check for invalid characters
274 valid = true
275 for end, c := range []byte(path[start+1:]) {
276 switch c {
277 case '/':
278 return path[start : start+1+end], start, valid
279 case ':', '*':
280 valid = false
281 }
282 }
283 return path[start:], start, valid
284 }
285 return "", -1, false
286}
287
288func (n *node) insertChild(path string, fullPath string, handlers HandlersChain) {
289 for {

Callers 1

insertChildMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected