-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcontext.go
More file actions
107 lines (89 loc) · 1.78 KB
/
Copy pathcontext.go
File metadata and controls
107 lines (89 loc) · 1.78 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package td
import (
"net/http"
"net/url"
)
type (
// Context
Context struct {
// Request
Request *http.Request
// ResponseWriter
ResponseWriter http.ResponseWriter
// index
index int
// http server
server *Server
// server plugins || handler
plugins Plugins
// save plugin data
values map[string]interface{}
}
)
// Plugin
type Plugin func(ctx *Context)
// Plugins
type Plugins []Plugin
// Next
func (c *Context) Next() {
c.index += 1
if c.index <= len(c.plugins) {
c.plugins[c.index-1](c)
}
}
// Head
func (c *Context) Head(key string) string {
return c.Request.Header.Get(key)
}
// HeadSet
func (c *Context) HeadSet(key, value string) {
c.ResponseWriter.Header().Set(key, value)
}
// ContentType
func (c *Context) ContentType() string {
return c.Request.Header.Get("Content-Type")
}
// ContentType
func (c *Context) ContentTypeSet(value string) {
c.ResponseWriter.Header().Set("Content-Type", value)
}
// GetRemoteIP
func (c *Context) GetRemoteIP() string {
return c.Request.RemoteAddr
}
// RemoteAddr
func (c *Context) RemoteAddr() string {
return c.Request.RemoteAddr
}
// RequestURI
func (c *Context) RequestURI() string {
return c.Request.RequestURI
}
// QueryValues
func (c *Context) QueryValues() url.Values {
return c.Request.URL.Query()
}
// Query
func (c *Context) Query(key string) string {
return c.Request.URL.Query().Get(key)
}
// Method
func (c *Context) Method() string {
return c.Request.Method
}
// UserAgent
func (c *Context) UserAgent() string {
return c.Request.UserAgent()
}
func (c *Context) SetValue(key string, val interface{}) {
if c.values == nil {
c.values = make(map[string]interface{})
}
c.values[key] = val
}
func (c *Context) GetValue(key string) interface{} {
if c.values == nil {
return nil
}
return c.values[key]
}