Skip to content

Commit ec527d4

Browse files
committed
Echo: Make it stop cheating
It used only the routing part of the framework before, not really the framework
1 parent c5a2f2c commit ec527d4

File tree

1 file changed

+35
-7
lines changed

1 file changed

+35
-7
lines changed

routers.go

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -281,25 +281,53 @@ func loadDencoSingle(method, path string, h denco.HandlerFunc) http.Handler {
281281
}
282282

283283
// Echo
284-
func echoHandler(*echo.Context) error { return nil }
284+
func echoHandler(c *echo.Context) error {
285+
return nil
286+
}
285287

286288
func echoHandlerWrite(c *echo.Context) error {
287289
io.WriteString(c.Response, c.Param("name"))
288290
return nil
289291
}
290292

291293
func loadEcho(routes []route) http.Handler {
292-
router := echo.New().Router
294+
e := echo.New()
293295
for _, r := range routes {
294-
router.Add(r.method, r.path, echoHandler, nil)
296+
switch r.method {
297+
case "GET":
298+
e.Get(r.path, echoHandler)
299+
case "POST":
300+
e.Post(r.path, echoHandler)
301+
case "PUT":
302+
e.Put(r.path, echoHandler)
303+
case "PATCH":
304+
e.Patch(r.path, echoHandler)
305+
case "DELETE":
306+
e.Delete(r.path, echoHandler)
307+
default:
308+
panic("Unknow HTTP method: " + r.method)
309+
}
295310
}
296-
return router
311+
return e
297312
}
298313

299-
func loadEchoSingle(method, path string, handler echo.HandlerFunc) http.Handler {
314+
func loadEchoSingle(method, path string, h interface{}) http.Handler {
300315
e := echo.New()
301-
e.MaxParam(20)
302-
e.Router.Add(method, path, echoHandler, nil)
316+
e.MaxParam(20) // TODO: technically illegal!
317+
switch method {
318+
case "GET":
319+
e.Get(path, h)
320+
case "POST":
321+
e.Post(path, h)
322+
case "PUT":
323+
e.Put(path, h)
324+
case "PATCH":
325+
e.Patch(path, h)
326+
case "DELETE":
327+
e.Delete(path, h)
328+
default:
329+
panic("Unknow HTTP method: " + method)
330+
}
303331
return e.Router
304332
}
305333

0 commit comments

Comments
 (0)