From: qydysky <32743305+qydysky@users.noreply.github.com> Date: Wed, 8 Feb 2023 19:00:06 +0000 (+0800) Subject: Fix X-Git-Tag: v0.22.5 X-Git-Url: http://127.0.0.1:8081/?a=commitdiff_plain;h=f3d884bb458dbe892e5a69fb8427260f64637b73;p=part%2F.git Fix --- diff --git a/web/Web.go b/web/Web.go index a467c63..7bc30f9 100644 --- a/web/Web.go +++ b/web/Web.go @@ -2,7 +2,6 @@ package part import ( "context" - "fmt" "net/http" "strconv" "sync" @@ -31,7 +30,6 @@ type WebPath struct { } func (t *WebPath) Load(path string) (func(w http.ResponseWriter, r *http.Request), bool) { - fmt.Println("l", t.path, path) t.l.RLock() if t.path == "" { t.l.RUnlock() @@ -41,7 +39,6 @@ func (t *WebPath) Load(path string) (func(w http.ResponseWriter, r *http.Request return t.f, true } else if len(path) > len(t.path) && path[:len(t.path)] == t.path { if t.path == "/" || path[len(t.path)] == '/' { - fmt.Println("-") if t.sameP != nil { if f, ok := t.sameP.Load(path); ok { t.l.RUnlock() @@ -81,7 +78,7 @@ func (t *WebPath) Store(path string, f func(w http.ResponseWriter, r *http.Reque t.f = f t.l.Unlock() } else if len(path) > len(t.path) && path[:len(t.path)] == t.path { - if path[len(t.path)-1] == '/' { + if t.path == "/" || path[len(t.path)] == '/' { if t.sameP != nil { t.l.RUnlock() t.sameP.Store(path, f) diff --git a/web/Web_test.go b/web/Web_test.go index ec557c5..cdb00d8 100644 --- a/web/Web_test.go +++ b/web/Web_test.go @@ -57,9 +57,16 @@ func Test_ServerSyncMapP(t *testing.T) { type d struct { A string `json:"path"` } + + NewSyncMap(&http.Server{ + Addr: "127.0.0.1:9090", + }, &m) m.Store("/", func(w http.ResponseWriter, r *http.Request) { ResStruct{0, "ok", d{"/"}}.Write(w) }) + m.Store("/1/2", func(w http.ResponseWriter, r *http.Request) { + ResStruct{0, "ok", d{"/1/2"}}.Write(w) + }) m.Store("/1", func(w http.ResponseWriter, r *http.Request) { ResStruct{0, "ok", d{"/1"}}.Write(w) }) @@ -67,10 +74,6 @@ func Test_ServerSyncMapP(t *testing.T) { ResStruct{0, "ok", d{"/2"}}.Write(w) }) - NewSyncMap(&http.Server{ - Addr: "127.0.0.1:9090", - }, &m) - time.Sleep(time.Second * time.Duration(23)) }