-
Notifications
You must be signed in to change notification settings - Fork 11
/
defaults.go
330 lines (257 loc) · 8.35 KB
/
defaults.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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
package defaults
import (
"context"
"github.com/admpub/realip"
"github.com/webx-top/echo"
"github.com/webx-top/echo/engine"
"github.com/webx-top/echo/logger"
)
var Default = echo.New()
func ParseHeaderAccept(on bool) *echo.Echo {
return Default.ParseHeaderAccept(on)
}
func SetValidator(validator echo.Validator) *echo.Echo {
return Default.SetValidator(validator)
}
func SetFormSliceMaxIndex(max int) *echo.Echo {
return Default.SetFormSliceMaxIndex(max)
}
func AddBinderValueDecoder(name string, decoder echo.BinderValueDecoder) *echo.Echo {
return Default.AddBinderValueDecoder(name, decoder)
}
func AddBinderValueEncoder(name string, encoder echo.BinderValueEncoder) *echo.Echo {
return Default.AddBinderValueEncoder(name, encoder)
}
func SetAcceptFormats(acceptFormats map[string]string) *echo.Echo {
return Default.SetAcceptFormats(acceptFormats)
}
func AddAcceptFormat(mime, format string) *echo.Echo {
return Default.AddAcceptFormat(mime, format)
}
func SetFormatRenderers(formatRenderers map[string]echo.FormatRender) *echo.Echo {
return Default.SetFormatRenderers(formatRenderers)
}
func AddFormatRenderer(format string, renderer echo.FormatRender) *echo.Echo {
return Default.AddFormatRenderer(format, renderer)
}
func SetMaxRequestBodySize(maxRequestSize int) *echo.Echo {
return Default.SetMaxRequestBodySize(maxRequestSize)
}
func MaxRequestBodySize() int {
return Default.MaxRequestBodySize()
}
func RemoveFormatRenderer(formats ...string) *echo.Echo {
return Default.RemoveFormatRenderer(formats...)
}
func SetDefaultExtension(ext string) {
Default.SetDefaultExtension(ext)
}
func DefaultExtension() string {
return Default.DefaultExtension()
}
// Router returns router.
func Router() *echo.Router {
return Default.Router()
}
// SetLogger sets the logger instance.
func SetLogger(l logger.Logger) {
Default.SetLogger(l)
}
// Logger returns the logger instance.
func Logger() logger.Logger {
return Default.Logger()
}
// DefaultHTTPErrorHandler invokes the default HTTP error handler.
func DefaultHTTPErrorHandler(err error, c echo.Context) {
Default.DefaultHTTPErrorHandler(err, c)
}
// SetHTTPErrorHandler registers a custom Echo.HTTPErrorHandler.
func SetHTTPErrorHandler(h echo.HTTPErrorHandler) {
Default.SetHTTPErrorHandler(h)
}
// HTTPErrorHandler returns the HTTPErrorHandler
func HTTPErrorHandler() echo.HTTPErrorHandler {
return Default.HTTPErrorHandler()
}
// SetBinder registers a custom binder. It's invoked by Context.Bind().
func SetBinder(b echo.Binder) {
Default.SetBinder(b)
}
// Binder returns the binder instance.
func Binder() echo.Binder {
return Default.Binder()
}
// SetRenderer registers an HTML template renderer. It's invoked by Context.Render().
func SetRenderer(r echo.Renderer) {
Default.SetRenderer(r)
}
// Renderer returns the renderer instance.
func Renderer() echo.Renderer {
return Default.Renderer()
}
// RenderDataWrapper .
func RenderDataWrapper() echo.DataWrapper {
return Default.RenderDataWrapper()
}
// SetRenderDataWrapper .
func SetRenderDataWrapper(dataWrapper echo.DataWrapper) {
Default.SetRenderDataWrapper(dataWrapper)
}
func SetRewriter(r echo.Rewriter) {
Default.SetRewriter(r)
}
func Rewriter() echo.Rewriter {
return Default.Rewriter()
}
// SetDebug enable/disable debug mode.
func SetDebug(on bool) {
Default.SetDebug(on)
}
// Debug returns debug mode (enabled or disabled).
func Debug() bool {
return Default.Debug()
}
// Use adds handler to the middleware chain.
func Use(middleware ...interface{}) {
Default.Use(middleware...)
}
// Pre is alias
func Pre(middleware ...interface{}) {
Default.Pre(middleware...)
}
// Clear middleware
func Clear(middleware ...interface{}) {
Default.Clear(middleware...)
}
// Connect adds a CONNECT route > handler to the router.
func Connect(path string, h interface{}, m ...interface{}) echo.IRouter {
return Default.Connect(path, h, m...)
}
// Delete adds a DELETE route > handler to the router.
func Delete(path string, h interface{}, m ...interface{}) echo.IRouter {
return Default.Delete(path, h, m...)
}
// Get adds a GET route > handler to the router.
func Get(path string, h interface{}, m ...interface{}) echo.IRouter {
return Default.Get(path, h, m...)
}
// Head adds a HEAD route > handler to the router.
func Head(path string, h interface{}, m ...interface{}) echo.IRouter {
return Default.Head(path, h, m...)
}
// Options adds an OPTIONS route > handler to the router.
func Options(path string, h interface{}, m ...interface{}) echo.IRouter {
return Default.Options(path, h, m...)
}
// Patch adds a PATCH route > handler to the router.
func Patch(path string, h interface{}, m ...interface{}) echo.IRouter {
return Default.Patch(path, h, m...)
}
// Post adds a POST route > handler to the router.
func Post(path string, h interface{}, m ...interface{}) echo.IRouter {
return Default.Post(path, h, m...)
}
// Put adds a PUT route > handler to the router.
func Put(path string, h interface{}, m ...interface{}) echo.IRouter {
return Default.Put(path, h, m...)
}
// Trace adds a TRACE route > handler to the router.
func Trace(path string, h interface{}, m ...interface{}) echo.IRouter {
return Default.Trace(path, h, m...)
}
// Any adds a route > handler to the router for all HTTP methods.
func Any(path string, h interface{}, m ...interface{}) echo.IRouter {
return Default.Any(path, h, m...)
}
func Route(methods string, path string, h interface{}, m ...interface{}) echo.IRouter {
return Default.Route(methods, path, h, m...)
}
// Match adds a route > handler to the router for multiple HTTP methods provided.
func Match(methods []string, path string, h interface{}, m ...interface{}) echo.IRouter {
return Default.Match(methods, path, h, m...)
}
func SetHandlerWrapper(funcs ...func(interface{}) echo.Handler) {
Default.SetHandlerWrapper(funcs...)
}
func SetMiddlewareWrapper(funcs ...func(interface{}) echo.Middleware) {
Default.SetMiddlewareWrapper(funcs...)
}
func AddHandlerWrapper(funcs ...func(interface{}) echo.Handler) {
Default.AddHandlerWrapper(funcs...)
}
func AddMiddlewareWrapper(funcs ...func(interface{}) echo.Middleware) {
Default.AddMiddlewareWrapper(funcs...)
}
func Prefix() string {
return Default.Prefix()
}
func SetPrefix(prefix string) *echo.Echo {
return Default.SetPrefix(prefix)
}
// MetaHandler Add meta information about endpoint
func MetaHandler(m echo.H, handler interface{}, requests ...interface{}) echo.Handler {
return Default.MetaHandler(m, handler, requests...)
}
// MetaHandlerWithRequest Add meta information about endpoint
func MetaHandlerWithRequest(m echo.H, handler interface{}, request interface{}, methods ...string) echo.Handler {
return Default.MetaHandlerWithRequest(m, handler, request, methods...)
}
// RebuildRouter rebuild router
func RebuildRouter(args ...[]*echo.Route) *echo.Echo {
return Default.RebuildRouter(args...)
}
func Host(name string, m ...interface{}) *echo.Group {
return Default.Host(name, m...)
}
func TypeHost(alias string, args ...interface{}) echo.TypeHost {
return Default.TypeHost(alias, args...)
}
func OnHostFound(onHostFound func(echo.Context) (bool, error)) *echo.Echo {
return Default.OnHostFound(onHostFound)
}
// Group creates a new sub-router with prefix.
func Group(prefix string, m ...interface{}) *echo.Group {
return Default.Group(prefix, m...)
}
// URI generates a URI from handler.
func URI(handler interface{}, params ...interface{}) string {
return Default.URI(handler, params...)
}
// URL is an alias for `URI` function.
func URL(h interface{}, params ...interface{}) string {
return Default.URL(h, params...)
}
// Routes returns the registered routes.
func Routes() []*echo.Route {
return Default.Routes()
}
// NamedRoutes returns the registered handler name.
func NamedRoutes() map[string][]int {
return Default.NamedRoutes()
}
func ServeHTTP(req engine.Request, res engine.Response) {
Default.ServeHTTP(req, res)
}
func Commit() *echo.Echo {
return Default.Commit()
}
// Run starts the HTTP engine.
func Run(eng engine.Engine, handler ...engine.Handler) error {
return Default.Run(eng, handler...)
}
func Engine() engine.Engine {
return Default.Engine()
}
// Stop stops the HTTP server.
func Stop() error {
return Default.Stop()
}
func Shutdown(ctx context.Context) error {
return Default.Shutdown(ctx)
}
func NewContext(req engine.Request, resp engine.Response) echo.Context {
return Default.NewContext(req, resp)
}
func RealIPConfig() *realip.Config {
return Default.RealIPConfig()
}