-
Notifications
You must be signed in to change notification settings - Fork 11
/
context.go
211 lines (183 loc) · 5.02 KB
/
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
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
package echo
import (
"context"
"io"
"mime/multipart"
"net/http"
"time"
"github.com/admpub/events"
"github.com/webx-top/echo/engine"
"github.com/webx-top/echo/logger"
"github.com/webx-top/echo/param"
)
// Context represents context for the current request. It holds request and
// response objects, path parameters, data and registered handler.
type Context interface {
context.Context
events.Emitter
SetEmitter(events.Emitter)
Transaction
SetTransaction(t Transaction)
StdContext() context.Context
SetStdContext(context.Context)
Validator
SetValidator(Validator)
Translator
SetTranslator(Translator)
Request() engine.Request
Response() engine.Response
Handle(Context) error
Logger() logger.Logger
Object() *xContext
Echo() *Echo
Route() *Route
Reset(engine.Request, engine.Response)
//----------------
// Param
//----------------
Path() string
P(int, ...string) string
Param(string, ...string) string
// ParamNames returns path parameter names.
ParamNames() []string
ParamValues() []string
SetParamValues(values ...string)
// Queries returns the query parameters as map. It is an alias for `engine.URL#Query()`.
Queries() map[string][]string
QueryValues(string) []string
QueryxValues(string) param.StringSlice
Query(string, ...string) string
//----------------
// Form data
//----------------
Form(string, ...string) string
FormValues(string) []string
FormxValues(string) param.StringSlice
// Forms returns the form parameters as map. It is an alias for `engine.Request#Form().All()`.
Forms() map[string][]string
// Param+
Px(int, ...string) param.String
Paramx(string, ...string) param.String
Queryx(string, ...string) param.String
Formx(string, ...string) param.String
// string to param.String
Atop(string) param.String
ToParamString(string) param.String
ToStringSlice([]string) param.StringSlice
//----------------
// Context data
//----------------
Set(string, interface{})
Get(string, ...interface{}) interface{}
Delete(...string)
Stored() Store
//----------------
// Bind
//----------------
Bind(interface{}, ...FormDataFilter) error
MustBind(interface{}, ...FormDataFilter) error
//----------------
// Response data
//----------------
Render(string, interface{}, ...int) error
HTML(string, ...int) error
String(string, ...int) error
Blob([]byte, ...int) error
JSON(interface{}, ...int) error
JSONBlob([]byte, ...int) error
JSONP(string, interface{}, ...int) error
XML(interface{}, ...int) error
XMLBlob([]byte, ...int) error
Stream(func(io.Writer) bool)
SSEvent(string, chan interface{}) error
File(string, ...http.FileSystem) error
Attachment(io.ReadSeeker, string) error
NoContent(...int) error
Redirect(string, ...int) error
Error(err error)
SetCode(int)
Code() int
SetData(Data)
Data() Data
// ServeContent sends static content from `io.Reader` and handles caching
// via `If-Modified-Since` request header. It automatically sets `Content-Type`
// and `Last-Modified` response headers.
ServeContent(io.ReadSeeker, string, time.Time) error
//----------------
// FuncMap
//----------------
SetFunc(string, interface{})
GetFunc(string) interface{}
ResetFuncs(map[string]interface{})
Funcs() map[string]interface{}
PrintFuncs()
//----------------
// Render
//----------------
SetAuto(on bool) Context
Fetch(string, interface{}) ([]byte, error)
SetRenderer(Renderer)
//----------------
// Cookie
//----------------
SetCookieOptions(*CookieOptions)
CookieOptions() *CookieOptions
NewCookie(string, string) *Cookie
Cookie() Cookier
GetCookie(string) string
SetCookie(string, string, ...interface{})
//----------------
// Session
//----------------
SetSessionOptions(*SessionOptions)
SessionOptions() *SessionOptions
SetSessioner(Sessioner)
Session() Sessioner
Flash(...string) interface{}
//----------------
// Request data
//----------------
Header(string) string
IsAjax() bool
IsPjax() bool
PjaxContainer() string
Method() string
Format() string
SetFormat(string)
IsPost() bool
IsGet() bool
IsPut() bool
IsDel() bool
IsHead() bool
IsPatch() bool
IsOptions() bool
IsSecure() bool
IsWebsocket() bool
IsUpload() bool
ResolveContentType() string
WithFormatExtension(bool)
ResolveFormat() string
Accept() *Accepts
Protocol() string
Site() string
Scheme() string
Domain() string
Host() string
Proxy() []string
Referer() string
Port() int
RealIP() string
HasAnyRequest() bool
MapForm(i interface{}, names ...string) error
MapData(i interface{}, data map[string][]string, names ...string) error
SaveUploadedFile(fieldName string, saveAbsPath string, saveFileName ...string) (*multipart.FileHeader, error)
SaveUploadedFileToWriter(string, io.Writer) (*multipart.FileHeader, error)
//Multiple file upload
SaveUploadedFiles(fieldName string, savePath func(*multipart.FileHeader) (string, error)) error
SaveUploadedFilesToWriter(fieldName string, writer func(*multipart.FileHeader) (io.Writer, error)) error
//----------------
// Hook
//----------------
AddPreResponseHook(func() error) Context
SetPreResponseHook(...func() error) Context
}