]> 127.0.0.1 Git - part/.git/commitdiff
Fix v0.22.5
authorqydysky <32743305+qydysky@users.noreply.github.com>
Wed, 8 Feb 2023 19:00:06 +0000 (03:00 +0800)
committerqydysky <32743305+qydysky@users.noreply.github.com>
Wed, 8 Feb 2023 19:00:06 +0000 (03:00 +0800)
web/Web.go
web/Web_test.go

index a467c63b1df051cb65c91244b85ea40626793be8..7bc30f9f144adda089bf3f6ca3b5fef7acda1fb6 100644 (file)
@@ -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)
index ec557c56d10d3b9215c6aac9bf59d81b919f2a7e..cdb00d851e47241add31066980adbf2e26679024 100644 (file)
@@ -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))
 }