mirror of
https://github.com/labstack/echo.git
synced 2024-12-24 20:14:31 +02:00
e1d789ecbb
Signed-off-by: Vishal Rana <vr@labstack.com>
1.6 KiB
1.6 KiB
title | menu | ||||||
---|---|---|---|---|---|---|---|
Migrating |
|
Migrating from v1
What got changed?
- Echo now uses
Engine
interface to abstractHTTP
server implementation, allowing us to use HTTP servers beyond Go standard library, supports standard HTTP server and FastHTTP. - Context, Request and Response as an interface, enabling adding your own functions and easy testing. More...
- Moved API's for serving static files into middleware.
Echo#Index
Echo#Favicon
Echo#Static
Echo#ServeDir
Echo#ServeFile
- Dropped auto wrapping of handler and middleware to enforce compile time check.
- Handler only accepts
Echo#Handler
interface. - Middleware only accepts
Echo#Middleware
interface. Echo#HandlerFunc
adapter to use of ordinary functions as handlers.Echo#MiddlewareFunc
adapter to use of ordinary functions as middleware.- Middleware is run before hitting the router, which doesn't require
Echo#Hook
API as it can be achieved via middleware. - Ability to define middleware at route level.
How?
v1 Handler
func welcome(c *echo.Context) error {
return c.String(http.StatusOK, "Welcome!\n")
}
v2 Handler
func welcome(echo.HandlerFunc(c echo.Context) error {
return c.String(http.StatusOK, "Welcome!\n")
})
v1 Middleware
func welcome(c *echo.Context) error {
return c.String(http.StatusOK, "Welcome!\n")
}
v2
func welcome(echo.HandlerFunc(c echo.Context) error {
return c.String(http.StatusOK, "Welcome!\n")
})