Browse Source

En cours de développement

master
losyme 5 months ago
parent
commit
5afadc6fe0
  1. 5
      router/router.go
  2. 8
      router/serve.go

5
router/router.go

@ -7,7 +7,6 @@
package router
import (
"fmt"
"net/http"
"strings"
@ -42,8 +41,6 @@ func (r *Router) NewSubRouter(prefix string, rrt context.RendererType) (*SubRout
sr := newSubRouter(rrt)
r.srMap[prefix] = sr
fmt.Println("==>", "nsr", len(sr.middlewares)) //AFAC
return sr, nil
}
@ -51,9 +48,7 @@ func (r *Router) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
path := req.URL.Path
for prefix, sr := range r.srMap {
fmt.Println("==>", path, prefix, len(sr.middlewares)) //AFAC
if strings.HasPrefix(path, prefix) {
fmt.Println("==>", prefix) //AFAC
sr.ServeHTTP(rw, req)
return
}

8
router/serve.go

@ -7,7 +7,6 @@
package router
import (
"fmt"
"net/http"
"strings"
@ -69,21 +68,15 @@ func (sr *SubRouter) serve(c *context.Context, handler HandlerFunc, mdlw []Middl
}
func (sr *SubRouter) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
fmt.Println("==>", "a", len(sr.middlewares)) //AFAC
c := sr.ctxPool.Get(rw, req, sr.rrType)
defer sr.ctxPool.Put(c)
ms := _msPool.Get().(*middlewares)
defer _msPool.Put(ms.reset())
fmt.Println("==>", "b", len(ms.list)) //AFAC
ms.list = append(ms.list, sr.middlewares...)
seg := sr.match(req.URL.Path, c, ms)
fmt.Println("==>", "c", len(ms.list)) //AFAC
if seg == nil || seg.handlers == nil {
sr.serve(c, sr.notFound, sr.middlewares)
return
@ -91,7 +84,6 @@ func (sr *SubRouter) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
handler, ok := seg.handlers[strings.ToUpper(req.Method)]
if ok {
fmt.Println("==>", "d", len(ms.list)) //AFAC
sr.serve(c, handler, ms.list)
return
}

Loading…
Cancel
Save