Handle registers a new request handle with the given path and method. For GET, POST, PUT, PATCH and DELETE requests the respective shortcut functions can be used. This function is intended for bulk loading and to allow the usage of less frequently used, non-standardized or custom methods (e.g. for
(method, path string, handle Handle)
| 242 | // frequently used, non-standardized or custom methods (e.g. for internal |
| 243 | // communication with a proxy). |
| 244 | func (r *Router) Handle(method, path string, handle Handle) { |
| 245 | if len(path) < 1 || path[0] != '/' { |
| 246 | panic("path must begin with '/' in path '" + path + "'") |
| 247 | } |
| 248 | |
| 249 | if r.trees == nil { |
| 250 | r.trees = make(map[string]*node) |
| 251 | } |
| 252 | |
| 253 | root := r.trees[method] |
| 254 | if root == nil { |
| 255 | root = new(node) |
| 256 | r.trees[method] = root |
| 257 | |
| 258 | r.globalAllowed = r.allowed("*", "") |
| 259 | } |
| 260 | |
| 261 | root.addRoute(path, handle) |
| 262 | } |
| 263 | |
| 264 | // Handler is an adapter which allows the usage of an http.Handler as a |
| 265 | // request handle. |