custom not found
This commit is contained in:
@@ -6,12 +6,14 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Router struct {
|
type Router struct {
|
||||||
t *tree
|
t *tree
|
||||||
|
NotFound http.HandlerFunc
|
||||||
}
|
}
|
||||||
|
|
||||||
func New() *Router {
|
func New() *Router {
|
||||||
return &Router{
|
return &Router{
|
||||||
t: newTree(),
|
t: newTree(),
|
||||||
|
NotFound: http.NotFound,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -22,7 +24,7 @@ func (rt *Router) Add(path string, foo http.HandlerFunc) error {
|
|||||||
func (rt *Router) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
func (rt *Router) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
foo := rt.t.Lookup(r.URL.Path)
|
foo := rt.t.Lookup(r.URL.Path)
|
||||||
if foo == nil {
|
if foo == nil {
|
||||||
http.NotFound(w, r)
|
rt.NotFound(w, r)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
foo(w, r)
|
foo(w, r)
|
||||||
|
|||||||
Reference in New Issue
Block a user