-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathctx.go
55 lines (44 loc) · 1.06 KB
/
ctx.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
51
52
53
54
55
package vitali
import (
"net/http"
)
type Ctx struct {
Username string
Roles Roles
Request *http.Request
ResponseWriter http.ResponseWriter
ChosenType MediaType
ChosenLang string
ContentType MediaType
pathParams map[string]string
}
func (c *Ctx) AddHeader(key string, value string) {
c.ResponseWriter.Header().Add(key, value)
}
func (c *Ctx) Cookie(name string) (value string) {
cookie, _ := c.Request.Cookie(name)
if cookie == nil {
return ""
} else {
return cookie.Value
}
}
func (c *Ctx) SetCookie(cookie *http.Cookie) {
http.SetCookie(c.ResponseWriter, cookie)
}
func (c *Ctx) Param(key string) string {
return c.Request.Form.Get(key)
}
func (c *Ctx) HasParam(key string) bool {
_, exists := c.Request.Form[key]
return exists
}
func (c *Ctx) ParamArray(key string) []string {
return c.Request.Form[key]
}
func (c *Ctx) PathParam(key string) string {
return c.pathParams[key]
}
func (c *Ctx) Header(key string) string {
return c.Request.Header.Get(key)
}