How about make a new 404 router like Beego?
@leoycx Please explain in detail!
e.GET("Error404", func(c echo.Context) error {
return ...
})
you never need to set up a router of not found error, it's a status of requested page
package main
import (
"net/http"
"github.com/labstack/echo"
"github.com/labstack/echo/engine/standard"
)
func main() {
echo.NotFoundHandler = func(c echo.Context) error {
// render your 404 page
return c.String(http.StatusNotFound, "not found page")
}
e := echo.New()
e.GET("/something/:id", func(c echo.Context) error {
if c.Param("id") == "5" {
return echo.NotFoundHandler(c)
}
return c.String(http.StatusOK, c.Param("id"))
})
e.Run(standard.New(":8000"))
}
also see default error handler https://github.com/labstack/echo/blob/master/echo.go#L276, you can customize it setting own error handler using e.SetHTTPErrorHandler
You Can also pass error URL Name. like
echo.NotFoundHandler = func(c echo.Context) error {
user_input = c.Request().URL // http.URL
msg = "not found page :" , user_input
// render your 404 page
return c.String(http.StatusNotFound, msg )
}
Most helpful comment
You Can also pass error URL Name. like
echo.NotFoundHandler = func(c echo.Context) error { user_input = c.Request().URL // http.URL msg = "not found page :" , user_input // render your 404 page return c.String(http.StatusNotFound, msg ) }