-
Notifications
You must be signed in to change notification settings - Fork 0
/
context.go
50 lines (45 loc) · 977 Bytes
/
context.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
47
48
49
50
package stgin
import (
"mime/multipart"
"net/http"
"time"
)
type RequestContext struct {
Url string
QueryParams map[string][]string
PathParams map[string]string
Headers http.Header
Body *RequestBody
receivedAt time.Time
Method string
ContentLength int64
Host string
MultipartForm func() *multipart.Form
}
func (c RequestContext) GetPathParam(name string) (string, bool) {
var res string
var found bool
for paramName, value := range c.PathParams {
if paramName == name {
found = true
res = value
break
}
}
return res, found
}
func (c RequestContext) GetQueries(name string) []string {
var res []string
for queryName, values := range c.QueryParams {
if queryName == name {
res = values
}
}
return res
}
func (c RequestContext) GetQuery(name string) (string, bool) {
allValues := c.GetQueries(name)
if len(allValues) == 1 {
return allValues[0], true
} else { return "", false }
}