(goctl)feature/model config (#4062)

Co-authored-by: Kevin Wan <wanjunfeng@gmail.com>
This commit is contained in:
kesonan
2024-04-10 23:01:59 +08:00
committed by GitHub
parent 682460c1c8
commit 2a7ada993b
12 changed files with 574 additions and 36 deletions

View File

@@ -1,12 +1,27 @@
package gen
import (
"fmt"
"strings"
"github.com/zeromicro/go-zero/tools/goctl/model/sql/template"
"github.com/zeromicro/go-zero/tools/goctl/util"
"github.com/zeromicro/go-zero/tools/goctl/util/pathx"
)
func genImports(table Table, withCache, timeImport bool) (string, error) {
var thirdImports []string
var m = map[string]struct{}{}
for _, c := range table.Fields {
if len(c.ThirdPkg) > 0 {
if _, ok := m[c.ThirdPkg]; ok {
continue
}
m[c.ThirdPkg] = struct{}{}
thirdImports = append(thirdImports, fmt.Sprintf("%q", c.ThirdPkg))
}
}
if withCache {
text, err := pathx.LoadTemplate(category, importsTemplateFile, template.Imports)
if err != nil {
@@ -17,6 +32,7 @@ func genImports(table Table, withCache, timeImport bool) (string, error) {
"time": timeImport,
"containsPQ": table.ContainsPQ,
"data": table,
"third": strings.Join(thirdImports, "\n"),
})
if err != nil {
return "", err
@@ -34,6 +50,7 @@ func genImports(table Table, withCache, timeImport bool) (string, error) {
"time": timeImport,
"containsPQ": table.ContainsPQ,
"data": table,
"third": strings.Join(thirdImports, "\n"),
})
if err != nil {
return "", err