2020-07-29 17:11:41 +08:00
|
|
|
package gen
|
|
|
|
|
|
|
|
import (
|
2020-08-19 10:41:19 +08:00
|
|
|
"github.com/tal-tech/go-zero/tools/goctl/model/sql/template"
|
2020-10-19 23:13:18 +08:00
|
|
|
"github.com/tal-tech/go-zero/tools/goctl/util"
|
2022-01-03 21:32:40 +08:00
|
|
|
"github.com/tal-tech/go-zero/tools/goctl/util/pathx"
|
2020-07-29 17:11:41 +08:00
|
|
|
)
|
|
|
|
|
2020-09-03 13:57:28 +08:00
|
|
|
func genImports(withCache, timeImport bool) (string, error) {
|
2020-08-19 10:41:19 +08:00
|
|
|
if withCache {
|
2022-01-03 21:32:40 +08:00
|
|
|
text, err := pathx.LoadTemplate(category, importsTemplateFile, template.Imports)
|
2020-10-21 14:59:35 +08:00
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
|
|
|
buffer, err := util.With("import").Parse(text).Execute(map[string]interface{}{
|
2020-09-03 13:57:28 +08:00
|
|
|
"time": timeImport,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
2020-10-21 14:59:35 +08:00
|
|
|
|
2020-09-03 13:57:28 +08:00
|
|
|
return buffer.String(), nil
|
2021-02-09 13:50:21 +08:00
|
|
|
}
|
2020-10-21 14:59:35 +08:00
|
|
|
|
2022-01-03 21:32:40 +08:00
|
|
|
text, err := pathx.LoadTemplate(category, importsWithNoCacheTemplateFile, template.ImportsNoCache)
|
2021-02-09 13:50:21 +08:00
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
2020-10-21 14:59:35 +08:00
|
|
|
|
2021-02-09 13:50:21 +08:00
|
|
|
buffer, err := util.With("import").Parse(text).Execute(map[string]interface{}{
|
|
|
|
"time": timeImport,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
2020-07-29 17:11:41 +08:00
|
|
|
}
|
2021-02-09 13:50:21 +08:00
|
|
|
|
|
|
|
return buffer.String(), nil
|
2020-07-29 17:11:41 +08:00
|
|
|
}
|