-
Notifications
You must be signed in to change notification settings - Fork 0
/
hander.go
28 lines (24 loc) · 921 Bytes
/
hander.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
package router
import (
"net/http"
"github.com/gorilla/context"
"github.com/julienschmidt/httprouter"
)
// HandlerFunc accepts the name of a function so you don't have to wrap it with http.HandlerFunc
// Example: r.GET("/", httprouterwrapper.HandlerFunc(controller.Index))
// Source: http://nicolasmerouze.com/guide-routers-golang/
func HandlerFunc(h http.HandlerFunc) httprouter.Handle {
return func(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
context.Set(r, params, p)
h.ServeHTTP(w, r)
}
}
// Handler accepts a handler to make it compatible with http.HandlerFunc
// Example: r.GET("/", httprouterwrapper.Handler(http.HandlerFunc(controller.Index)))
// Source: http://nicolasmerouze.com/guide-routers-golang/
func Handler(h http.Handler) httprouter.Handle {
return func(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
context.Set(r, params, p)
h.ServeHTTP(w, r)
}
}