]> 127.0.0.1 Git - part/.git/commitdiff
Improve ServerSyncMap v0.22.2
authorqydysky <32743305+qydysky@users.noreply.github.com>
Mon, 6 Feb 2023 14:31:07 +0000 (22:31 +0800)
committerqydysky <32743305+qydysky@users.noreply.github.com>
Mon, 6 Feb 2023 14:31:07 +0000 (22:31 +0800)
web/Web.go
web/Web_test.go

index 4831e55dbb5ade7f3c098644b65776cb84cf13f3..3fa2ee3d4b52f049d86eb24303b6d906acb566d1 100644 (file)
@@ -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)
                        }
                }
index a5a4cfe001c303cfc25b87f935b00d90842f6df1..520c3d4b540503fb65b6b8b9c819928a1b3c2ef7 100644 (file)
@@ -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)))
                })
        }