category_factory.go 527 B

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