aboutsummaryrefslogtreecommitdiff
path: root/router/router.go
diff options
context:
space:
mode:
Diffstat (limited to 'router/router.go')
-rw-r--r--router/router.go16
1 files changed, 8 insertions, 8 deletions
diff --git a/router/router.go b/router/router.go
index d984ad0..f0ba53b 100644
--- a/router/router.go
+++ b/router/router.go
@@ -10,6 +10,7 @@ import (
"path"
"os"
"errors"
+ "context"
)
type Router struct {
@@ -24,7 +25,6 @@ type Router struct {
StaticPaths map[string]string
}
-
type Route struct {
path *regexp.Regexp
handlerMap map[string]http.Handler
@@ -125,7 +125,7 @@ func (self *Router) ServeHTTP(w http.ResponseWriter, req *http.Request) {
}
for method, handler := range r.handlerMap {
if method == req.Method {
- /* Parse the form and add the params to it */
+ /* Parse the form and add the params to the context */
req.ParseForm()
ProcessParams(req, params)
/* handle the request! */
@@ -142,9 +142,7 @@ func (self *Router) ServeHTTP(w http.ResponseWriter, req *http.Request) {
*******************/
func ProcessParams(req *http.Request, params map[string]string) {
- for key, value := range params {
- req.Form.Add(key, value)
- }
+ *req = *req.WithContext(context.WithValue(req.Context(), "params", params))
}
func (self *Route) Match(r *http.Request) map[string]string {
@@ -165,8 +163,10 @@ func (self *Route) Match(r *http.Request) map[string]string {
func (self *Router) ErrorPage(w http.ResponseWriter, req *http.Request, code int, errMsg string) {
w.WriteHeader(code)
- req.ParseForm()
- req.Form.Add("ErrorCode", strconv.Itoa(code))
- req.Form.Add("ErrorMessage", errMsg)
+ params := map[string]string{
+ "ErrorCode": strconv.Itoa(code),
+ "ErrorMessage": errMsg,
+ }
+ ProcessParams(req, params)
self.Fallback.Execute(w, req)
}