github.com/lucasscarioca/music-stash@v0.0.0-20230829021135-a8b8893b12a5/internal/routes/middlewares/cacheControl.go (about) 1 package middlewares 2 3 import ( 4 "fmt" 5 "time" 6 7 "github.com/labstack/echo/v4" 8 ) 9 10 func CacheControl(maxAge time.Duration) echo.MiddlewareFunc { 11 return func(next echo.HandlerFunc) echo.HandlerFunc { 12 return func(c echo.Context) error { 13 v := "no-cache, no-store" 14 if maxAge > 0 { 15 v = fmt.Sprintf("public, max-age=%.0f", maxAge.Seconds()) 16 } 17 c.Response().Header().Set("Cache-Control", v) 18 return next(c) 19 } 20 } 21 }