Files
SiteProxy/proxy/stats.go
2025-12-15 01:19:58 +08:00

30 lines
583 B
Go

// proxy/stats.go
package proxy
import (
"encoding/json"
"net/http"
"siteproxy/cache"
)
type StatsHandler struct {
cache *cache.MemoryCache
}
func NewStatsHandler(cache *cache.MemoryCache) *StatsHandler {
return &StatsHandler{cache: cache}
}
func (h *StatsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
entries, size := h.cache.Stats()
stats := map[string]interface{}{
"entries": entries,
"size": size,
}
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(stats)
}