Fix issues (#931)
* fix #929 * fix #925 * add test case * update model README * fix #929 * fix #929 * fix #929 * refactor dir * Adding todo comments Co-authored-by: anqiansong <anqiansong@xiaoheiban.cn>
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
|
||||
"github.com/tal-tech/go-zero/tools/goctl/api/spec"
|
||||
"github.com/tal-tech/go-zero/tools/goctl/config"
|
||||
"github.com/tal-tech/go-zero/tools/goctl/internal/env"
|
||||
"github.com/tal-tech/go-zero/tools/goctl/util"
|
||||
"github.com/tal-tech/go-zero/tools/goctl/util/format"
|
||||
"github.com/tal-tech/go-zero/tools/goctl/vars"
|
||||
@@ -17,6 +18,7 @@ const handlerTemplate = `package handler
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
{{if .After1_1_10}}"github.com/tal-tech/go-zero/rest/httpx"{{end}}
|
||||
{{.ImportPackages}}
|
||||
)
|
||||
|
||||
@@ -47,6 +49,7 @@ type handlerInfo struct {
|
||||
Call string
|
||||
HasResp bool
|
||||
HasRequest bool
|
||||
After1_1_10 bool
|
||||
}
|
||||
|
||||
func genHandler(dir, rootPkg string, cfg *config.Config, group spec.Group, route spec.Route) error {
|
||||
@@ -55,9 +58,13 @@ func genHandler(dir, rootPkg string, cfg *config.Config, group spec.Group, route
|
||||
handler = strings.Title(handler)
|
||||
}
|
||||
|
||||
goctlVersion := env.GetGoctlVersion()
|
||||
// todo(anqiansong): This will be removed after a certain number of production versions of goctl (probably 5)
|
||||
after1_1_10 := env.IsVersionGatherThan(goctlVersion, "1.1.10")
|
||||
return doGenToFile(dir, handler, cfg, group, route, handlerInfo{
|
||||
ImportPackages: genHandlerImports(group, route, rootPkg),
|
||||
HandlerName: handler,
|
||||
After1_1_10: after1_1_10,
|
||||
RequestType: util.Title(route.RequestTypeName()),
|
||||
LogicType: strings.Title(getLogicName(route)),
|
||||
Call: strings.Title(strings.TrimSuffix(handler, "Handler")),
|
||||
@@ -105,7 +112,12 @@ func genHandlerImports(group spec.Group, route spec.Route, parentPkg string) str
|
||||
if len(route.RequestTypeName()) > 0 {
|
||||
imports = append(imports, fmt.Sprintf("\"%s\"\n", util.JoinPackages(parentPkg, typesDir)))
|
||||
}
|
||||
imports = append(imports, fmt.Sprintf("\"%s/rest/httpx\"", vars.ProjectOpenSourceURL))
|
||||
|
||||
currentVersion := env.GetGoctlVersion()
|
||||
// todo(anqiansong): This will be removed after a certain number of production versions of goctl (probably 5)
|
||||
if !env.IsVersionGatherThan(currentVersion, "1.1.10") {
|
||||
imports = append(imports, fmt.Sprintf("\"%s/rest/httpx\"", vars.ProjectOpenSourceURL))
|
||||
}
|
||||
|
||||
return strings.Join(imports, "\n\t")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user