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

Method addRoute

gin.go:364–386  ·  view source on GitHub ↗
(method, path string, handlers HandlersChain)

Source from the content-addressed store, hash-verified

362}
363
364func (engine *Engine) addRoute(method, path string, handlers HandlersChain) {
365 assert1(path[0] == '/', "path must begin with '/'")
366 assert1(method != "", "HTTP method can not be empty")
367 assert1(len(handlers) > 0, "there must be at least one handler")
368
369 debugPrintRoute(method, path, handlers)
370
371 root := engine.trees.get(method)
372 if root == nil {
373 root = new(node)
374 root.fullPath = "/"
375 engine.trees = append(engine.trees, methodTree{method: method, root: root})
376 }
377 root.addRoute(path, handlers)
378
379 if paramsCount := countParams(path); paramsCount > engine.maxParams {
380 engine.maxParams = paramsCount
381 }
382
383 if sectionsCount := countSections(path); sectionsCount > engine.maxSections {
384 engine.maxSections = sectionsCount
385 }
386}
387
388// Routes returns a slice of registered routes, including some useful information, such as:
389// the http method, path, and the handler name.

Callers

nothing calls this directly

Calls 5

assert1Function · 0.85
debugPrintRouteFunction · 0.85
countParamsFunction · 0.85
countSectionsFunction · 0.85
getMethod · 0.80

Tested by

no test coverage detected