路由小优化
This commit is contained in:
parent
87f639da58
commit
036f1a1212
2
.gitignore
vendored
2
.gitignore
vendored
@ -2,4 +2,4 @@
|
|||||||
wp-go.iml
|
wp-go.iml
|
||||||
config.yaml
|
config.yaml
|
||||||
err.log
|
err.log
|
||||||
plugins
|
./plugins/
|
@ -1,36 +0,0 @@
|
|||||||
module plugintt
|
|
||||||
|
|
||||||
go 1.20
|
|
||||||
|
|
||||||
require github.com/fthvgb1/wp-go latest
|
|
||||||
|
|
||||||
require (
|
|
||||||
github.com/dlclark/regexp2 v1.7.0 // indirect
|
|
||||||
github.com/elliotchance/phpserialize v1.3.3 // indirect
|
|
||||||
github.com/gin-contrib/sessions v0.0.5 // indirect
|
|
||||||
github.com/gin-contrib/sse v0.1.0 // indirect
|
|
||||||
github.com/gin-gonic/gin v1.8.1 // indirect
|
|
||||||
github.com/go-playground/locales v0.14.0 // indirect
|
|
||||||
github.com/go-playground/universal-translator v0.18.0 // indirect
|
|
||||||
github.com/go-playground/validator/v10 v10.11.1 // indirect
|
|
||||||
github.com/goccy/go-json v0.9.11 // indirect
|
|
||||||
github.com/gorilla/context v1.1.1 // indirect
|
|
||||||
github.com/gorilla/securecookie v1.1.1 // indirect
|
|
||||||
github.com/gorilla/sessions v1.2.1 // indirect
|
|
||||||
github.com/jmoiron/sqlx v1.3.5 // indirect
|
|
||||||
github.com/json-iterator/go v1.1.12 // indirect
|
|
||||||
github.com/leodido/go-urn v1.2.1 // indirect
|
|
||||||
github.com/mattn/go-isatty v0.0.16 // indirect
|
|
||||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
|
||||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
|
||||||
github.com/pelletier/go-toml/v2 v2.0.5 // indirect
|
|
||||||
github.com/shopspring/decimal v1.3.1 // indirect
|
|
||||||
github.com/ugorji/go/codec v1.2.7 // indirect
|
|
||||||
golang.org/x/crypto v0.0.0-20220924013350-4ba4fb4dd9e7 // indirect
|
|
||||||
golang.org/x/exp v0.0.0-20230203172020-98cc5a0785f9 // indirect
|
|
||||||
golang.org/x/net v0.5.0 // indirect
|
|
||||||
golang.org/x/sys v0.4.0 // indirect
|
|
||||||
golang.org/x/text v0.6.0 // indirect
|
|
||||||
google.golang.org/protobuf v1.28.1 // indirect
|
|
||||||
gopkg.in/yaml.v2 v2.4.0 // indirect
|
|
||||||
)
|
|
@ -65,7 +65,6 @@ func config(h *wp.Handle) {
|
|||||||
Scene: constraints.Home,
|
Scene: constraints.Home,
|
||||||
Method: []string{"GET"},
|
Method: []string{"GET"},
|
||||||
Type: "reg",
|
Type: "reg",
|
||||||
ConfigHandle: wp.Index,
|
|
||||||
})
|
})
|
||||||
//...
|
//...
|
||||||
}
|
}
|
||||||
|
@ -12,8 +12,7 @@ type Route struct {
|
|||||||
Path string
|
Path string
|
||||||
Scene string
|
Scene string
|
||||||
Method []string
|
Method []string
|
||||||
Type string //const|reg
|
Type string
|
||||||
ConfigHandle func(*wp.Handle)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var routeHook []func(Route) (Route, bool)
|
var routeHook []func(Route) (Route, bool)
|
||||||
@ -36,7 +35,6 @@ var routes = func() *safety.Map[string, Route] {
|
|||||||
// Scene: constraints.Home,
|
// Scene: constraints.Home,
|
||||||
// Method: []string{"GET"},
|
// Method: []string{"GET"},
|
||||||
// Type: "reg",
|
// Type: "reg",
|
||||||
// ConfigHandle: $theme.Hook or nil,
|
|
||||||
// }
|
// }
|
||||||
func PushRoute(path string, route Route) error {
|
func PushRoute(path string, route Route) error {
|
||||||
if route.Type == "const" {
|
if route.Type == "const" {
|
||||||
@ -112,7 +110,7 @@ func ResolveRoute(h *wp.Handle) {
|
|||||||
v, ok := rs[requestURI]
|
v, ok := rs[requestURI]
|
||||||
if ok && slice.IsContained(v.Method, h.C.Request.Method) {
|
if ok && slice.IsContained(v.Method, h.C.Request.Method) {
|
||||||
h.SetScene(v.Scene)
|
h.SetScene(v.Scene)
|
||||||
wp.Run(h, v.ConfigHandle)
|
wp.Run(h, nil)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
for path, reg := range rrs {
|
for path, reg := range rrs {
|
||||||
@ -124,7 +122,7 @@ func ResolveRoute(h *wp.Handle) {
|
|||||||
if slice.IsContained(rr.Method, h.C.Request.Method) {
|
if slice.IsContained(rr.Method, h.C.Request.Method) {
|
||||||
h.SetScene(rr.Scene)
|
h.SetScene(rr.Scene)
|
||||||
h.C.Set("route", r)
|
h.C.Set("route", r)
|
||||||
wp.Run(h, rr.ConfigHandle)
|
wp.Run(h, nil)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user