-
Notifications
You must be signed in to change notification settings - Fork 0
/
request.go
46 lines (37 loc) · 836 Bytes
/
request.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
38
39
40
41
42
43
44
45
46
package muxer
import (
"github.com/gorilla/mux"
"net/http"
)
type Request struct {
Request *http.Request
Params map[string]string
QueryString map[string]string
}
// CurrentRoute allows to retrieve the current
// from a request
func (r *Request) CurrentRoute() *mux.Route {
return mux.CurrentRoute(r.Request)
}
func (r *Request) GetHost() string {
return getHost(r.Request)
}
func (r *Request) IsAjax() bool {
return matchMap(map[string]string{
"HTTP_X_REQUESTED_WITH": "XMLHttpRequest",
}, r.Request.Header, true)
}
func NewRequest(req *http.Request) *Request {
req.ParseForm()
queryString := make(map[string]string)
if len(req.Form) > 0 {
for k, v := range req.Form {
queryString[k] = v[0]
}
}
return &Request{
Request: req,
QueryString: queryString,
Params: mux.Vars(req),
}
}