(path string, fullPath string, handlers HandlersChain)
| 286 | } |
| 287 | |
| 288 | func (n *node) insertChild(path string, fullPath string, handlers HandlersChain) { |
| 289 | for { |
| 290 | // Find prefix until first wildcard |
| 291 | wildcard, i, valid := findWildcard(path) |
| 292 | if i < 0 { // No wildcard found |
| 293 | break |
| 294 | } |
| 295 | |
| 296 | // The wildcard name must only contain one ':' or '*' character |
| 297 | if !valid { |
| 298 | panic("only one wildcard per path segment is allowed, has: '" + |
| 299 | wildcard + "' in path '" + fullPath + "'") |
| 300 | } |
| 301 | |
| 302 | // check if the wildcard has a name |
| 303 | if len(wildcard) < 2 { |
| 304 | panic("wildcards must be named with a non-empty name in path '" + fullPath + "'") |
| 305 | } |
| 306 | |
| 307 | if wildcard[0] == ':' { // param |
| 308 | if i > 0 { |
| 309 | // Insert prefix before the current wildcard |
| 310 | n.path = path[:i] |
| 311 | path = path[i:] |
| 312 | } |
| 313 | |
| 314 | child := &node{ |
| 315 | nType: param, |
| 316 | path: wildcard, |
| 317 | fullPath: fullPath, |
| 318 | } |
| 319 | n.addChild(child) |
| 320 | n.wildChild = true |
| 321 | n = child |
| 322 | n.priority++ |
| 323 | |
| 324 | // if the path doesn't end with the wildcard, then there |
| 325 | // will be another subpath starting with '/' |
| 326 | if len(wildcard) < len(path) { |
| 327 | path = path[len(wildcard):] |
| 328 | |
| 329 | child := &node{ |
| 330 | priority: 1, |
| 331 | fullPath: fullPath, |
| 332 | } |
| 333 | n.addChild(child) |
| 334 | n = child |
| 335 | continue |
| 336 | } |
| 337 | |
| 338 | // Otherwise we're done. Insert the handle in the new leaf |
| 339 | n.handlers = handlers |
| 340 | return |
| 341 | } |
| 342 | |
| 343 | // catchAll |
| 344 | if i+len(wildcard) != len(path) { |
| 345 | panic("catch-all routes are only allowed at the end of the path in path '" + fullPath + "'") |
no test coverage detected