imports.go 939 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  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]interface{}{
  14. "time": timeImport,
  15. "data": table,
  16. })
  17. if err != nil {
  18. return "", err
  19. }
  20. return buffer.String(), nil
  21. }
  22. text, err := pathx.LoadTemplate(category, importsWithNoCacheTemplateFile, template.ImportsNoCache)
  23. if err != nil {
  24. return "", err
  25. }
  26. buffer, err := util.With("import").Parse(text).Execute(map[string]interface{}{
  27. "time": timeImport,
  28. "data": table,
  29. })
  30. if err != nil {
  31. return "", err
  32. }
  33. return buffer.String(), nil
  34. }