forked from gobuffalo/buffalo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwrappers.go
35 lines (30 loc) · 939 Bytes
/
wrappers.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
28
29
30
31
32
33
34
35
package buffalo
import "net/http"
// WrapHandler wraps a standard http.Handler and transforms it
// into a buffalo.Handler.
func WrapHandler(h http.Handler) Handler {
return func(c Context) error {
h.ServeHTTP(c.Response(), c.Request())
return nil
}
}
// WrapHandlerFunc wraps a standard http.HandlerFunc and
// transforms it into a buffalo.Handler.
func WrapHandlerFunc(h http.HandlerFunc) Handler {
return WrapHandler(h)
}
// WrapBuffaloHandler wraps a buffalo.Handler to
// standard http.Handler
func WrapBuffaloHandler(h Handler) http.Handler {
a := New(Options{})
// it doesn't matter what we actually map it
// GET, POST, etc... we just need the underlying
// RouteInfo, which implements http.Handler
ri := a.GET("/", h)
return ri
}
// WrapBuffaloHandlerFunc wraps a buffalo.Handler to
// standard http.HandlerFunc
func WrapBuffaloHandlerFunc(h Handler) http.HandlerFunc {
return WrapBuffaloHandler(h).ServeHTTP
}