fix: goctl genhandler duplicate rest/httpx & goctl genhandler template support custom import httpx package (#2152)

master
杨圆建 2 years ago committed by GitHub
parent 2a6f801978
commit bc85eaa9b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -23,6 +23,7 @@ var handlerTemplate string
type handlerInfo struct {
PkgName string
ImportPackages string
ImportHttpxPackage string
HandlerName string
RequestType string
LogicName string
@ -49,6 +50,7 @@ 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,
@ -99,7 +101,6 @@ func genHandlerImports(group spec.Group, route spec.Route, parentPkg string) str
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")
}

@ -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 {

Loading…
Cancel
Save