imports.go 826 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. package gen
  2. import (
  3. "git.i2edu.net/i2/go-zero/tools/goctl/model/sql/template"
  4. "git.i2edu.net/i2/go-zero/tools/goctl/util"
  5. )
  6. func genImports(withCache, timeImport bool) (string, error) {
  7. if withCache {
  8. text, err := util.LoadTemplate(category, importsTemplateFile, template.Imports)
  9. if err != nil {
  10. return "", err
  11. }
  12. buffer, err := util.With("import").Parse(text).Execute(map[string]interface{}{
  13. "time": timeImport,
  14. })
  15. if err != nil {
  16. return "", err
  17. }
  18. return buffer.String(), nil
  19. }
  20. text, err := util.LoadTemplate(category, importsWithNoCacheTemplateFile, template.ImportsNoCache)
  21. if err != nil {
  22. return "", err
  23. }
  24. buffer, err := util.With("import").Parse(text).Execute(map[string]interface{}{
  25. "time": timeImport,
  26. })
  27. if err != nil {
  28. return "", err
  29. }
  30. return buffer.String(), nil
  31. }