Vibhu Pandey bfeceb0ed2
feat(web): add web package (#5743)
### Summary

Add a web package for serving frontend

#### Related Issues / PR's

https://github.com/SigNoz/signoz/pull/5710
2024-08-22 20:56:15 +05:30

29 lines
510 B
Go

package middleware
import (
"net/http"
"strconv"
"time"
)
type Cache struct {
maxAge time.Duration
}
func NewCache(maxAge time.Duration) *Cache {
if maxAge == 0 {
maxAge = 7 * 24 * time.Hour
}
return &Cache{
maxAge: maxAge,
}
}
func (middleware *Cache) Wrap(next http.Handler) http.Handler {
return http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
rw.Header().Set("Cache-Control", "max-age="+strconv.Itoa(int(middleware.maxAge.Seconds())))
next.ServeHTTP(rw, req)
})
}