diff --git a/httpr.go b/httpr.go index ff8024e..e9b995d 100644 --- a/httpr.go +++ b/httpr.go @@ -157,22 +157,21 @@ func (rr *Router) ServeHTTP(w http.ResponseWriter, r *http.Request) { } // Handler registers a handler for provided pattern for a given HTTP method. -func (rr *Router) Handler(method, pattern string, handler http.HandlerFunc) { - if pattern[0] != '/' { - panic("first element of path should be a slash (/) symbol") - } - - if strings.Count(pattern, "*") > 1 { - panic("there can be only one wildcard (*) symbol in path") +func (rr *Router) Handler(method, pattern string, handler http.HandlerFunc) error { + path, err := newPath(pattern) + if err != nil { + return err } if rr.tree[method] == nil { rr.tree[method] = &node{endpoint: "/"} } - path, _ := newPath(pattern) + if err := rr.tree[method].add(path, handler); err != nil { + return err + } - rr.tree[method].add(path, 0, handler) + return nil } // ServeStatic serves a given file system.