Browse Source

tsweb: add ReturnHandlerFunc.

Signed-off-by: David Anderson <[email protected]>
David Anderson 5 years ago
parent
commit
eccae0cd0c
1 changed files with 11 additions and 0 deletions
  1. 11 0
      tsweb/tsweb.go

+ 11 - 0
tsweb/tsweb.go

@@ -164,6 +164,17 @@ func StdHandler(h ReturnHandler, logf logger.Logf) http.Handler {
 	return stdHandler(h, logf, time.Now, true)
 }
 
+// ReturnHandlerFunc is an adapter to allow the use of ordinary
+// functions as ReturnHandlers. If f is a function with the
+// appropriate signature, ReturnHandlerFunc(f) is a ReturnHandler that
+// calls f.
+type ReturnHandlerFunc func(http.ResponseWriter, *http.Request) error
+
+// ServeHTTPReturn calls f(w, r).
+func (f ReturnHandlerFunc) ServeHTTPReturn(w http.ResponseWriter, r *http.Request) error {
+	return f(w, r)
+}
+
 // StdHandlerNo200s is like StdHandler, but successfully handled HTTP
 // requests don't write an access log entry to logf.
 //