import (
"context"
- "fmt"
"net/http"
"strconv"
"sync"
}
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()
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()
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)
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)
})
ResStruct{0, "ok", d{"/2"}}.Write(w)
})
- NewSyncMap(&http.Server{
- Addr: "127.0.0.1:9090",
- }, &m)
-
time.Sleep(time.Second * time.Duration(23))
}