diff --git a/proxy/stats.go b/proxy/stats.go new file mode 100644 index 0000000..12a37a3 --- /dev/null +++ b/proxy/stats.go @@ -0,0 +1,29 @@ +// 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) +}