AddRoute registers a route for the given method and path.
(method, path string, handlers ...Handler)
| 286 | |
| 287 | // AddRoute registers a route for the given method and path. |
| 288 | func (server *Server) AddRoute(method, path string, handlers ...Handler) { |
| 289 | server.mutex.Lock() |
| 290 | defer server.mutex.Unlock() |
| 291 | |
| 292 | if !isValidMethod(method) { |
| 293 | server.errorLog.Printf("Invalid HTTP method: %s", method) |
| 294 | return |
| 295 | } |
| 296 | |
| 297 | route := &Route{ |
| 298 | Method: method, |
| 299 | Path: path, |
| 300 | Handlers: handlers, |
| 301 | } |
| 302 | server.routes = append(server.routes, route) |
| 303 | server.router.Insert(method, path, server.wrapHandlers(handlers)) |
| 304 | } |
| 305 | |
| 306 | func (server *Server) Get(path string, handlers ...Handler) { |
| 307 | server.AddRoute(MethodGet, path, handlers...) |