-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconvert.go
27 lines (23 loc) · 960 Bytes
/
convert.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package rmhttp
import "net/http"
// ------------------------------------------------------------------------------------------------
// CONVERSION FUNCTIONS
// ------------------------------------------------------------------------------------------------
// ConvertHandlerFunc converts, then returns, the passed Net/HTTP compatible HandlerFunc function
// to one that fulfils the rmhttp.HandlerFunc signature
func ConvertHandlerFunc(
handlerFunc func(http.ResponseWriter, *http.Request),
) func(http.ResponseWriter, *http.Request) error {
return func(w http.ResponseWriter, r *http.Request) error {
handlerFunc(w, r)
return nil
}
}
// ConvertHandler converts, then returns, the passed http.Handler to a rmhttp.HandlerFunc, which
// implements the rmhttp.Handler interface.
func ConvertHandler(handler http.Handler) HandlerFunc {
return HandlerFunc(func(w http.ResponseWriter, r *http.Request) error {
handler.ServeHTTP(w, r)
return nil
})
}