From 5c67f876839fe3d592d0f0f287e30015dd398a16 Mon Sep 17 00:00:00 2001 From: Rogee Date: Mon, 23 Dec 2024 16:00:11 +0800 Subject: [PATCH] fix: gen routes --- pkg/ast/route/route.go | 31 ------------------------------- 1 file changed, 31 deletions(-) diff --git a/pkg/ast/route/route.go b/pkg/ast/route/route.go index 10be40b..9654e4a 100644 --- a/pkg/ast/route/route.go +++ b/pkg/ast/route/route.go @@ -5,12 +5,9 @@ import ( "go/ast" "go/parser" "go/token" - "path/filepath" - "regexp" "strings" "git.ipao.vip/rogeecn/atomctl/pkg/utils/gomod" - "github.com/iancoleman/strcase" "github.com/pkg/errors" "github.com/samber/lo" log "github.com/sirupsen/logrus" @@ -231,34 +228,6 @@ func parseRouteComment(line string) (string, string, error) { return parts[1], parts[2], nil } -func getPackageRoute(mod, path string) string { - paths := strings.SplitN(path, "modules", 2) - pkg := paths[1] - // path可能值为 - // /test/user_controller.go - // /test/modules/user_controller.go - - return strings.TrimLeft(filepath.Dir(pkg), "/") -} - -func formatRoute(route string) string { - pattern := regexp.MustCompile(`(?mi)\{(.*?)\}`) - if !pattern.MatchString(route) { - return route - } - - items := pattern.FindAllStringSubmatch(route, -1) - for _, item := range items { - param := strcase.ToLowerCamel(item[1]) - route = strings.ReplaceAll(route, item[0], fmt.Sprintf("{%s}", param)) - } - - route = pattern.ReplaceAllString(route, ":$1") - route = strings.ReplaceAll(route, "/:id", "/:id") - route = strings.ReplaceAll(route, "Id/", "Id/") - return route -} - func parseRouteBind(bind string) ParamDefinition { var param ParamDefinition parts := strings.FieldsFunc(bind, func(r rune) bool {