Skip to content

How to make Not Found detection take effect before middleware #2761

Open
@OneSeven

Description

@OneSeven
e := echo.New()
e.Use(func(next echo.HandlerFunc) echo.HandlerFunc {
	return func(c echo.Context) error {
		log.Println("middleware...")
		return next(c)
	}
})
e.GET("/hello", func(c echo.Context) error {
	return c.String(http.StatusOK, "Hello, World!")
})
e.Logger.Fatal(e.Start(":1323"))

http://127.0.0.1:1323/test

Accessing a non-existent route, but passing through the middleware first, this situation also applies to route groups

There is usually an authorization authentication in the middleware. If you access a non-existent route, it will go through the middleware first, which will waste unnecessary processing and add additional judgment logic.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions