From 7b11ea82f01fef8a6ec8c084ffba5c8f8f7d6b02 Mon Sep 17 00:00:00 2001 From: Max Date: Wed, 13 Dec 2023 13:03:06 +0800 Subject: [PATCH] [fix] route matching errors, reload matchers --- sui/api/process.go | 6 ++++++ sui/api/request.go | 8 ++++---- sui/api/sui.go | 5 +++++ 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/sui/api/process.go b/sui/api/process.go index 8871d30e..3501df0d 100644 --- a/sui/api/process.go +++ b/sui/api/process.go @@ -572,6 +572,8 @@ func PageCreate(process *process.Process) interface{} { if err != nil { exception.New(err.Error(), 500).Throw() } + + Reload() return nil } @@ -611,6 +613,7 @@ func PageRename(process *process.Process) interface{} { exception.New(err.Error(), 500).Throw() } + Reload() return nil } @@ -650,6 +653,7 @@ func PageDuplicate(process *process.Process) interface{} { exception.New(err.Error(), 500).Throw() } + Reload() return nil } @@ -673,6 +677,8 @@ func PageRemove(process *process.Process) interface{} { if err != nil { exception.New(err.Error(), 500).Throw() } + + Reload() return nil } diff --git a/sui/api/request.go b/sui/api/request.go index f26d2dc8..b9f98f81 100644 --- a/sui/api/request.go +++ b/sui/api/request.go @@ -125,7 +125,7 @@ func parserPath(c *gin.Context) (string, map[string]string, error) { parts := strings.Split(strings.TrimSuffix(c.Request.URL.Path, ".sui"), "/")[1:] if len(parts) < 1 { - return "", nil, fmt.Errorf("no route matchers") + return "", nil, fmt.Errorf("path parts error: %s", strings.Join(parts, "/")) } fileParts := []string{string(os.PathSeparator), "public"} @@ -146,7 +146,7 @@ func parserPath(c *gin.Context) (string, map[string]string, error) { // No matchers if matchers == nil { if len(parts) < 1 { - return "", nil, fmt.Errorf("no route matchers") + return "", nil, fmt.Errorf("path parts error: %s", strings.Join(parts, "/")) } fileParts = append(fileParts, parts...) @@ -156,7 +156,7 @@ func parserPath(c *gin.Context) (string, map[string]string, error) { // Match the page parts for i, part := range parts[1:] { if len(matchers) < i+1 { - return "", nil, fmt.Errorf("no route matchers") + return "", nil, fmt.Errorf("matchers length error %d < %d", len(matchers), i+1) } parent := "" @@ -189,7 +189,7 @@ func parserPath(c *gin.Context) (string, map[string]string, error) { } if !matched { - return "", nil, fmt.Errorf("no route matchers") + return "", nil, fmt.Errorf("route does not match") } } return filepath.Join(fileParts...) + ".sui", params, nil diff --git a/sui/api/sui.go b/sui/api/sui.go index d6606ccc..6a7e6a16 100644 --- a/sui/api/sui.go +++ b/sui/api/sui.go @@ -75,6 +75,11 @@ func loadFile(file string, id string) (core.SUI, error) { return core.SUIs[id], nil } +// Reload reload the route matchers +func Reload() { + buildRouteMatchers() +} + func buildRouteMatchers() (map[*regexp.Regexp][][]*core.Matcher, map[string][][]*core.Matcher) { matchers := map[*regexp.Regexp][][]*core.Matcher{} exactMatchers := map[string][][]*core.Matcher{}