package middleware

import (
	"path/filepath"
	"strings"

	"github.com/gin-gonic/gin"
)

func StaticCacheControl() gin.HandlerFunc {
	return func(c *gin.Context) {
		ext := strings.ToLower(filepath.Ext(c.Request.URL.Path))
		switch ext {
		case ".css", ".js", ".png", ".jpg", ".jpeg", ".gif", ".svg", ".webp", ".ico":
			c.Header("Cache-Control", "public, max-age=31536000, immutable")
			c.Header("Vary", "Accept-Encoding")
		}
		c.Next()
	}
}
