Closed
Description
I have several groups and some groups use specific middlewares.
But I noticed that in some combination of mw some groups start using middlewares from another groups.
For example:
files:
/static/test.txt
main.go
code:
package main
import (
"log"
"github.com/labstack/echo"
mw "github.com/labstack/echo/middleware"
)
func main() {
e := echo.New()
e.Use(mw.Logger())
e.Use(mw.Recover())
e.Use(mw.Gzip())
static := e.Group("/static")
static.Use(MaxAgeMonth)
static.ServeDir("/", "static")
e.Get("/", func(c *echo.Context) error {
return c.String(200, "Index")
})
admStatic := e.Group("/admin/static")
admStatic.Use(MaxAgeMonth)
admStatic.ServeDir("/", "admin/static")
a := e.Group("/admin")
a.Use(func(c *echo.Context) error {
log.Println("Admin")
return nil
})
a.Get("/info", func(c *echo.Context) error {
return c.String(200, "OK")
})
e.Run(":8085")
}
func MaxAgeMonth(c *echo.Context) error {
c.Response().Header().Add("Cache-Control", "max-age=2592000, public")
return nil
}
So, if you open http://127.0.0.1:8085/static/test.txt
You'll see "Admin" in console. It means that /static/test.txt use another middleware which is in "/admin" group.
But if I remove e.Use(mw.Recover()) or e.Use(mw.Gzip()) everything works ok.
It's really odd.