From a9808a894dfc58c4f848da0de262260598a09db1 Mon Sep 17 00:00:00 2001 From: XOF Date: Mon, 15 Dec 2025 01:19:58 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20proxy/stats.go?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- proxy/stats.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 proxy/stats.go 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) +}