-
-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathbuild.go
37 lines (33 loc) · 1 KB
/
build.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
36
37
package minima
import "net/http"
/**
* @info Converts minima handler into middleware chain handler
* @param {Handler} [h] The handler to convert
* @param {map[string]string} [params] The handler params
* @return {func(http.Handler) http.Handler}
*/
func build(h Handler, params map[string]string) func(http.Handler) http.Handler {
return func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
resp := response(w, req)
reqs := request(req)
reqs.Params = params
h(resp, reqs)
next.ServeHTTP(w, req)
})
}
}
/**
* @info Converts minima handler into net/http handler func
* @param {Handler} [h] The handler to convert
* @param {map[string]string} [params] The handler params
* @return {http.Handler}
*/
func buildHandler(h Handler, params map[string]string) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
resp := response(w, req)
reqs := request(req)
reqs.Params = params
h(resp, reqs)
})
}