From 1f40810b78e705af0ec4a156ecf11d863c81c696 Mon Sep 17 00:00:00 2001 From: xing Date: Thu, 18 Apr 2024 11:48:49 +0800 Subject: [PATCH] optimize wp reg route --- app/theme/wp/route/route.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/app/theme/wp/route/route.go b/app/theme/wp/route/route.go index 9889c7a..63cfa01 100644 --- a/app/theme/wp/route/route.go +++ b/app/theme/wp/route/route.go @@ -33,8 +33,8 @@ var routes = func() *safety.Map[string, Route] { // PushRoute path can be const or regex string // -// eg: `(?P\w+)/(?P\w+)`, route.Route{ -// Path: `(?P\w+)/(?P\w+)`, +// eg: `(?P\w+)/(?P\w+)`, route.Route{ +// Path: `(?P\w+)/(?P\w+)`, // Scene: constraints.Home, // Method: []string{"GET"}, // Type: "reg", @@ -121,14 +121,21 @@ func ResolveRoute(h *wp.Handle) { return } for path, reg := range rrs { - r := reg.FindAllStringSubmatch(requestURI, -1) + r := reg.FindStringSubmatch(requestURI) if len(r) < 1 { return } rr := rs[path] if slice.IsContained(rr.Method, h.C.Request.Method) { h.SetScene(rr.Scene) - h.C.Set("route", r) + for i, name := range reg.SubexpNames() { + if name == "" { + continue + } + h.C.AddParam(name, r[i]) + } + h.C.Set("regRoute", reg) + h.C.Set("regRouteRes", r) wp.Run(h, nil) h.Abort() return