@@ -9,14 +9,14 @@ Echo is a fast HTTP router (zero memory allocation) and micro web framework in G
9
9
- `echo.MiddlewareFunc`
10
10
- `func(echo.HandlerFunc) echo.HandlerFunc`
11
11
- `echo.HandlerFunc`
12
- - `func(*echo.Context) *echo.HTTPError `
12
+ - `func(*echo.Context) error `
13
13
- `func(http.Handler) http.Handler`
14
14
- `http.Handler`
15
15
- `http.HandlerFunc`
16
16
- `func(http.ResponseWriter, *http.Request)`
17
17
- Handler
18
18
- `echo.HandlerFunc`
19
- - `func(*echo.Context) *echo.HTTPError `
19
+ - `func(*echo.Context) error `
20
20
- `http.Handler`
21
21
- `http.HandlerFunc`
22
22
- `func(http.ResponseWriter, *http.Request)`
@@ -84,7 +84,7 @@ import (
84
84
)
85
85
86
86
// Handler
87
- func hello (c *echo .Context ) * echo . HTTPError {
87
+ func hello (c *echo .Context ) error {
88
88
return c.String (http.StatusOK , " Hello, World!\n " )
89
89
}
90
90
@@ -133,34 +133,34 @@ var (
133
133
// Handlers
134
134
// ----------
135
135
136
- func createUser (c *echo .Context ) * echo . HTTPError {
136
+ func createUser (c *echo .Context ) error {
137
137
u := &user{
138
138
ID: seq,
139
139
}
140
- if he := c.Bind (u); he != nil {
141
- return he
140
+ if err := c.Bind (u); err != nil {
141
+ return err
142
142
}
143
143
users[u.ID ] = u
144
144
seq++
145
145
return c.JSON (http.StatusCreated , u)
146
146
}
147
147
148
- func getUser (c *echo .Context ) * echo . HTTPError {
148
+ func getUser (c *echo .Context ) error {
149
149
id , _ := strconv.Atoi (c.Param (" id" ))
150
150
return c.JSON (http.StatusOK , users[id])
151
151
}
152
152
153
- func updateUser (c *echo .Context ) * echo . HTTPError {
153
+ func updateUser (c *echo .Context ) error {
154
154
u := new (user)
155
- if he := c.Bind (u); he != nil {
156
- return he
155
+ if err := c.Bind (u); err != nil {
156
+ return err
157
157
}
158
158
id , _ := strconv.Atoi (c.Param (" id" ))
159
159
users[id].Name = u.Name
160
160
return c.JSON (http.StatusOK , users[id])
161
161
}
162
162
163
- func deleteUser (c *echo .Context ) * echo . HTTPError {
163
+ func deleteUser (c *echo .Context ) error {
164
164
id , _ := strconv.Atoi (c.Param (" id" ))
165
165
delete (users, id)
166
166
return c.NoContent (http.StatusNoContent )
@@ -218,22 +218,19 @@ var (
218
218
)
219
219
220
220
// Render HTML
221
- func (t *Template ) Render (w io .Writer , name string , data interface {}) *echo .HTTPError {
222
- if err := t.templates .ExecuteTemplate (w, name, data); err != nil {
223
- return &echo.HTTPError {Error: err}
224
- }
225
- return nil
221
+ func (t *Template ) Render (w io .Writer , name string , data interface {}) error {
222
+ return t.templates .ExecuteTemplate (w, name, data)
226
223
}
227
224
228
225
// ----------
229
226
// Handlers
230
227
// ----------
231
228
232
- func welcome (c *echo .Context ) * echo . HTTPError {
229
+ func welcome (c *echo .Context ) error {
233
230
return c.Render (http.StatusOK , " welcome" , " Joe" )
234
231
}
235
232
236
- func createUser (c *echo .Context ) * echo . HTTPError {
233
+ func createUser (c *echo .Context ) error {
237
234
u := new (user)
238
235
if err := c.Bind (u); err != nil {
239
236
return err
@@ -242,11 +239,11 @@ func createUser(c *echo.Context) *echo.HTTPError {
242
239
return c.JSON (http.StatusCreated , u)
243
240
}
244
241
245
- func getUsers (c *echo .Context ) * echo . HTTPError {
242
+ func getUsers (c *echo .Context ) error {
246
243
return c.JSON (http.StatusOK , users)
247
244
}
248
245
249
- func getUser (c *echo .Context ) * echo . HTTPError {
246
+ func getUser (c *echo .Context ) error {
250
247
return c.JSON (http.StatusOK , users[c.P (0 )])
251
248
}
252
249
@@ -268,7 +265,7 @@ func main() {
268
265
s := stats.New ()
269
266
e.Use (s.Handler )
270
267
// Route
271
- e.Get (" /stats" , func (c *echo.Context ) *echo. HTTPError {
268
+ e.Get (" /stats" , func (c *echo.Context ) error {
272
269
return c.JSON (http.StatusOK , s.Data ())
273
270
})
274
271
@@ -297,7 +294,7 @@ func main() {
297
294
// Cached templates
298
295
templates: template.Must (template.ParseFiles (" public/views/welcome.html" )),
299
296
}
300
- e.Renderer (t)
297
+ e.SetRenderer (t)
301
298
e.Get (" /welcome" , welcome)
302
299
303
300
// -------
@@ -306,20 +303,20 @@ func main() {
306
303
307
304
// Group with parent middleware
308
305
a := e.Group (" /admin" )
309
- a.Use (func (c *echo.Context ) *echo. HTTPError {
306
+ a.Use (func (c *echo.Context ) error {
310
307
// Security middleware
311
308
return nil
312
309
})
313
- a.Get (" " , func (c *echo.Context ) *echo. HTTPError {
310
+ a.Get (" " , func (c *echo.Context ) error {
314
311
return c.String (http.StatusOK , " Welcome admin!" )
315
312
})
316
313
317
314
// Group with no parent middleware
318
- g := e.Group (" /files" , func (c *echo.Context ) *echo. HTTPError {
315
+ g := e.Group (" /files" , func (c *echo.Context ) error {
319
316
// Security middleware
320
317
return nil
321
318
})
322
- g.Get (" " , func (c *echo.Context ) *echo. HTTPError {
319
+ g.Get (" " , func (c *echo.Context ) error {
323
320
return c.String (http.StatusOK , " Your files!" )
324
321
})
325
322
@@ -350,7 +347,7 @@ import (
350
347
)
351
348
352
349
// Handler
353
- func hello (c *echo .Context ) * echo . HTTPError {
350
+ func hello (c *echo .Context ) error {
354
351
return c.String (http.StatusOK , " Hello, World!\n " )
355
352
}
356
353
@@ -359,7 +356,7 @@ func main() {
359
356
e := echo.New ()
360
357
361
358
// Debug mode
362
- e.Debug (true )
359
+ e.SetDebug (true )
363
360
364
361
// ------------
365
362
// Middleware
0 commit comments