custom not found

master
Bel LaPointe 2021-04-20 05:49:09 -05:00
parent 5deb0e5f0d
commit b77f3987c9
1 changed files with 5 additions and 3 deletions

View File

@ -7,11 +7,13 @@ import (
type Router struct {
t *tree
NotFound http.HandlerFunc
}
func New() *Router {
return &Router{
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) {
foo := rt.t.Lookup(r.URL.Path)
if foo == nil {
http.NotFound(w, r)
rt.NotFound(w, r)
return
}
foo(w, r)