From 24aafe392c66a2395de330a7b7ba0734d867d5cf Mon Sep 17 00:00:00 2001 From: qydysky <32743305+qydysky@users.noreply.github.com> Date: Mon, 6 Feb 2023 22:31:07 +0800 Subject: [PATCH] Improve ServerSyncMap --- web/Web.go | 1 + web/Web_test.go | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/web/Web.go b/web/Web.go index 4831e55..3fa2ee3 100644 --- a/web/Web.go +++ b/web/Web.go @@ -76,6 +76,7 @@ func NewSyncMap(conf *http.Server, m *sync.Map) (o *Web) { o.mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { if wr, ok := m.Load(r.URL.Path); ok { if f, ok := wr.(func(http.ResponseWriter, *http.Request)); ok { + r.URL.Path = "/" f(w, r) } } diff --git a/web/Web_test.go b/web/Web_test.go index a5a4cfe..520c3d4 100644 --- a/web/Web_test.go +++ b/web/Web_test.go @@ -36,7 +36,9 @@ func Test_ServerSyncMap(t *testing.T) { }, &m) for i := 0; i < 20; i++ { time.Sleep(time.Second) - m.Store("/", func(w http.ResponseWriter, r *http.Request) { + m.Store("/1", func(w http.ResponseWriter, r *http.Request) { + t.Log(r.URL.Path) + t.Log(r.URL.EscapedPath()) w.Write([]byte(strconv.Itoa(i))) }) } -- 2.39.2