mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-06-22 23:51:17 +08:00

### Summary Add a web package for serving frontend #### Related Issues / PR's https://github.com/SigNoz/signoz/pull/5710
29 lines
510 B
Go
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)
|
|
})
|
|
}
|