From 9c448c64ef171ff4a4bb10d54053bfc181b3eeaf Mon Sep 17 00:00:00 2001 From: anqiansong Date: Tue, 19 Jul 2022 23:49:20 +0800 Subject: [PATCH] Update api template (#2172) --- tools/goctl/api/gogen/genhandlers.go | 20 +++++++++----------- tools/goctl/api/gogen/handler.tpl | 2 +- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/tools/goctl/api/gogen/genhandlers.go b/tools/goctl/api/gogen/genhandlers.go index 560ffe94..eae2c2fd 100644 --- a/tools/goctl/api/gogen/genhandlers.go +++ b/tools/goctl/api/gogen/genhandlers.go @@ -12,7 +12,6 @@ import ( "github.com/zeromicro/go-zero/tools/goctl/util" "github.com/zeromicro/go-zero/tools/goctl/util/format" "github.com/zeromicro/go-zero/tools/goctl/util/pathx" - "github.com/zeromicro/go-zero/tools/goctl/vars" ) const defaultLogicPackage = "logic" @@ -48,16 +47,15 @@ func genHandler(dir, rootPkg string, cfg *config.Config, group spec.Group, route } return doGenToFile(dir, handler, cfg, group, route, handlerInfo{ - PkgName: pkgName, - ImportPackages: genHandlerImports(group, route, parentPkg), - ImportHttpxPackage: fmt.Sprintf("\"%s/rest/httpx\"", vars.ProjectOpenSourceURL), - HandlerName: handler, - RequestType: util.Title(route.RequestTypeName()), - LogicName: logicName, - LogicType: strings.Title(getLogicName(route)), - Call: strings.Title(strings.TrimSuffix(handler, "Handler")), - HasResp: len(route.ResponseTypeName()) > 0, - HasRequest: len(route.RequestTypeName()) > 0, + PkgName: pkgName, + ImportPackages: genHandlerImports(group, route, parentPkg), + HandlerName: handler, + RequestType: util.Title(route.RequestTypeName()), + LogicName: logicName, + LogicType: strings.Title(getLogicName(route)), + Call: strings.Title(strings.TrimSuffix(handler, "Handler")), + HasResp: len(route.ResponseTypeName()) > 0, + HasRequest: len(route.RequestTypeName()) > 0, }) } diff --git a/tools/goctl/api/gogen/handler.tpl b/tools/goctl/api/gogen/handler.tpl index 3a9f9bac..033dc22e 100644 --- a/tools/goctl/api/gogen/handler.tpl +++ b/tools/goctl/api/gogen/handler.tpl @@ -3,8 +3,8 @@ package {{.PkgName}} import ( "net/http" + "github.com/zeromicro/go-zero/rest/httpx" {{.ImportPackages}} - {{.ImportHttpxPackage}} ) func {{.HandlerName}}(svcCtx *svc.ServiceContext) http.HandlerFunc {