topic_factory.go 535 B

123456789101112131415161718192021222324252627
  1. // Package factories 存放 topic 工厂方法
  2. package factories
  3. import (
  4. "github.com/bxcodec/faker/v4"
  5. "github.com/runningwater/gohub/app/models/topic"
  6. )
  7. func MakeTopics(times int) []topic.Topic {
  8. var objs []topic.Topic
  9. // 设置唯一值, 如 Topic 模型中的某个字段需要唯一
  10. faker.SetGenerateUniqueValues(true)
  11. for range times {
  12. model := topic.Topic{
  13. Title: faker.Sentence(),
  14. Body: faker.Paragraph(),
  15. UserID: "1",
  16. CategoryID: "3",
  17. }
  18. objs = append(objs, model)
  19. }
  20. return objs
  21. }