changed param logic & add more routes

This commit is contained in:
2026-09-04 18:08:20 +08:00
parent 86cde9bb97
commit a28c1dec9b
14 changed files with 269 additions and 12 deletions

View File

@@ -1,6 +1,7 @@
package routes
import (
"regexp"
"runtime"
"strings"
)
@@ -8,15 +9,12 @@ import (
func PathOf() string {
_, file, _, _ := runtime.Caller(1)
// 取 routes/ 之後的部分
idx := strings.Index(file, "routes/")
if idx == -1 {
return "/"
}
path := file[idx+len("routes"):]
// 去掉 .go
path = strings.TrimSuffix(path, ".go")
re := regexp.MustCompile(`param_(\w+)`)
path = re.ReplaceAllString(path, ":$1")
return path
}