vars.go 887 B

123456789101112131415161718192021222324252627282930313233
  1. package gen
  2. import (
  3. "strings"
  4. "github.com/tal-tech/go-zero/tools/goctl/model/sql/template"
  5. "github.com/tal-tech/go-zero/tools/goctl/util"
  6. "github.com/tal-tech/go-zero/tools/goctl/util/stringx"
  7. )
  8. func genVars(table Table, withCache bool) (string, error) {
  9. keys := make([]string, 0)
  10. for _, v := range table.CacheKey {
  11. keys = append(keys, v.VarExpression)
  12. }
  13. camel := table.Name.ToCamel()
  14. output, err := util.With("var").
  15. Parse(template.Vars).
  16. GoFmt(true).
  17. Execute(map[string]interface{}{
  18. "lowerStartCamelObject": stringx.From(camel).UnTitle(),
  19. "upperStartCamelObject": camel,
  20. "cacheKeys": strings.Join(keys, "\n"),
  21. "autoIncrement": table.PrimaryKey.AutoIncrement,
  22. "originalPrimaryKey": table.PrimaryKey.Name.Source(),
  23. "withCache": withCache,
  24. })
  25. if err != nil {
  26. return "", err
  27. }
  28. return output.String(), nil
  29. }