A type httprouter.Routeris one structthat has a field:
NotFound http.HandlerFunc
So, NotFoundis http.HandlerFunca function type with a signature:
type HandlerFunc func(ResponseWriter, *Request)
"Not Found", .
:
func MyNotFound(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
w.WriteHeader(http.StatusNotFound)
w.Write([]byte("My own Not Found handler."))
w.Write([]byte(" The page you requested could not be found."))
}
var router *httprouter.Router = ...
router.NotFound = MyNotFound
NotFound httprouter. , ResponseWriter *Request, - :
func ResourceHandler(w http.ResponseWriter, r *http.Request) {
exists := ...
if !exists {
MyNotFound(w, r)
return
}
}