go-zero/tools/goctl/model/sql/gen/imports.go

39 lines
832 B
Go
Raw Normal View History

2020-07-29 17:11:41 +08:00
package gen
import (
"github.com/tal-tech/go-zero/tools/goctl/model/sql/template"
"github.com/tal-tech/go-zero/tools/goctl/util"
2020-07-29 17:11:41 +08:00
)
func genImports(withCache, timeImport bool) (string, error) {
if withCache {
text, err := util.LoadTemplate(category, importsTemplateFile, template.Imports)
if err != nil {
return "", err
}
buffer, err := util.With("import").Parse(text).Execute(map[string]interface{}{
"time": timeImport,
})
if err != nil {
return "", err
}
return buffer.String(), nil
2021-02-09 13:50:21 +08:00
}
2021-02-09 13:50:21 +08:00
text, err := util.LoadTemplate(category, importsWithNoCacheTemplateFile, template.ImportsNoCache)
if err != nil {
return "", err
}
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
}