From d485285740f98d247e77a1413e3d77bc74a5a2b9 Mon Sep 17 00:00:00 2001 From: Jeremy Date: Sun, 31 Mar 2024 20:26:10 +0700 Subject: [PATCH] add adapter function to wrap http.HandleFunc and http.Handle into a handle --- router.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/router.go b/router.go index 818448a4..1ac845a3 100644 --- a/router.go +++ b/router.go @@ -357,6 +357,20 @@ func (r *Router) HandlerFunc(method, path string, handler http.HandlerFunc) { r.Handler(method, path, handler) } +// WrapF is an adapter function that converts a http.HandlerFunc into a Handle. +func WrapF(f http.HandlerFunc) Handle { + return func(w http.ResponseWriter, r *http.Request, _ Params) { + f(w, r) + } +} + +// WrapF is an adapter function that converts a http.Handler into a Handle. +func WrapH(h http.Handler) Handle { + return func(w http.ResponseWriter, r *http.Request, _ Params) { + h.ServeHTTP(w, r) + } +} + // ServeFiles serves files from the given file system root. // The path must end with "/*filepath", files are then served from the local // path /defined/root/dir/*filepath.