Insert registers handlers for a given HTTP method and path. Segments starting with ':' are treated as named parameters. A trailing '/*' is treated as a catch-all wildcard.
(method, path string, handlers []Handler)
| 28 | // Segments starting with ':' are treated as named parameters. |
| 29 | // A trailing '/*' is treated as a catch-all wildcard. |
| 30 | func (r *Router) Insert(method, path string, handlers []Handler) { |
| 31 | if path == "" { |
| 32 | path = "/" |
| 33 | } |
| 34 | // Trim leading slash so we work with the suffix only. |
| 35 | if path[0] == '/' { |
| 36 | path = path[1:] |
| 37 | } |
| 38 | r.root.insert(method, path, handlers, nil) |
| 39 | } |
| 40 | |
| 41 | // Search finds the handlers registered for method+path. |
| 42 | // Returns (handlers, params, found). |