From e0e3f97c7c0472557648bda47898b9a7bfd25a1c Mon Sep 17 00:00:00 2001 From: Kevin Wan Date: Sat, 2 Jul 2022 14:03:11 +0800 Subject: [PATCH] chore: refactor (#2087) --- tools/goctl/api/gogen/genhandlers.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/tools/goctl/api/gogen/genhandlers.go b/tools/goctl/api/gogen/genhandlers.go index 6cb1ee10..0231fc60 100644 --- a/tools/goctl/api/gogen/genhandlers.go +++ b/tools/goctl/api/gogen/genhandlers.go @@ -91,14 +91,15 @@ func genHandlers(dir, rootPkg string, cfg *config.Config, api *spec.ApiSpec) err } func genHandlerImports(group spec.Group, route spec.Route, parentPkg string) string { - var imports []string - imports = append(imports, fmt.Sprintf("\"%s\"", - pathx.JoinPackages(parentPkg, getLogicFolderPath(group, route)))) - imports = append(imports, fmt.Sprintf("\"%s\"", pathx.JoinPackages(parentPkg, contextDir))) + imports := []string{ + fmt.Sprintf("\"%s\"", pathx.JoinPackages(parentPkg, getLogicFolderPath(group, route))), + fmt.Sprintf("\"%s\"", pathx.JoinPackages(parentPkg, contextDir)), + } if len(route.RequestTypeName()) > 0 { imports = append(imports, fmt.Sprintf("\"%s\"\n", pathx.JoinPackages(parentPkg, typesDir))) } imports = append(imports, fmt.Sprintf("\"%s/rest/httpx\"", vars.ProjectOpenSourceURL)) + return strings.Join(imports, "\n\t") } @@ -107,6 +108,7 @@ func getHandlerBaseName(route spec.Route) (string, error) { handler = strings.TrimSpace(handler) handler = strings.TrimSuffix(handler, "handler") handler = strings.TrimSuffix(handler, "Handler") + return handler, nil } @@ -121,6 +123,7 @@ func getHandlerFolderPath(group spec.Group, route spec.Route) string { folder = strings.TrimPrefix(folder, "/") folder = strings.TrimSuffix(folder, "/") + return path.Join(handlerDir, folder) }