-
Notifications
You must be signed in to change notification settings - Fork 0
/
context.go
46 lines (41 loc) · 865 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
package stgin
import (
"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
}
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 }
}