Inversed logic of if else statement to reduce nesting by 1.
This commit is contained in:
parent
a2cb6182e8
commit
92692454da
10
httpr.go
10
httpr.go
@ -157,7 +157,12 @@ func New() *Router {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (rr *Router) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
func (rr *Router) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
if tree, ok := rr.tree[r.Method]; ok {
|
tree, ok := rr.tree[r.Method]
|
||||||
|
if !ok {
|
||||||
|
http.Error(w, http.StatusText(http.StatusMethodNotAllowed), http.StatusMethodNotAllowed)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
path, err := newPath(r.URL.Path)
|
path, err := newPath(r.URL.Path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, err.Error(), http.StatusNotAcceptable)
|
http.Error(w, err.Error(), http.StatusNotAcceptable)
|
||||||
@ -176,9 +181,6 @@ func (rr *Router) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
http.Error(w, "Not Found", http.StatusNotFound)
|
http.Error(w, "Not Found", http.StatusNotFound)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
http.Error(w, http.StatusText(http.StatusMethodNotAllowed), http.StatusMethodNotAllowed)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handler registers a handler for provided pattern for a given HTTP method.
|
// Handler registers a handler for provided pattern for a given HTTP method.
|
||||||
|
Loading…
Reference in New Issue
Block a user