imports.go 1016 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package gen
  2. import (
  3. "github.com/zeromicro/go-zero/tools/goctl/model/sql/template"
  4. "github.com/zeromicro/go-zero/tools/goctl/util"
  5. "github.com/zeromicro/go-zero/tools/goctl/util/pathx"
  6. )
  7. func genImports(table Table, withCache, timeImport bool) (string, error) {
  8. if withCache {
  9. text, err := pathx.LoadTemplate(category, importsTemplateFile, template.Imports)
  10. if err != nil {
  11. return "", err
  12. }
  13. buffer, err := util.With("import").Parse(text).Execute(map[string]any{
  14. "time": timeImport,
  15. "containsPQ": table.ContainsPQ,
  16. "data": table,
  17. })
  18. if err != nil {
  19. return "", err
  20. }
  21. return buffer.String(), nil
  22. }
  23. text, err := pathx.LoadTemplate(category, importsWithNoCacheTemplateFile, template.ImportsNoCache)
  24. if err != nil {
  25. return "", err
  26. }
  27. buffer, err := util.With("import").Parse(text).Execute(map[string]any{
  28. "time": timeImport,
  29. "containsPQ": table.ContainsPQ,
  30. "data": table,
  31. })
  32. if err != nil {
  33. return "", err
  34. }
  35. return buffer.String(), nil
  36. }