micrach/repositories/mocks.go

56 lines
1.1 KiB
Go
Raw Normal View History

2021-08-30 12:09:27 +03:00
package repositories
2021-08-31 19:18:27 +03:00
import (
"math/rand"
"time"
)
var letters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
func randSeq(n int) string {
b := make([]rune, n)
for i := range b {
b[i] = letters[rand.Intn(len(letters))]
}
return string(b)
}
2021-08-30 12:09:27 +03:00
func getFile(id, postId int, name string) File {
return File{
ID: id,
PostID: postId,
Name: name,
Ext: "image/jpeg",
Size: 10000,
CreatedAt: time.Now(),
}
}
2021-08-31 19:48:02 +03:00
func getPost(id int) Post {
2021-08-30 12:09:27 +03:00
return Post{
2021-08-31 19:48:02 +03:00
ID: id,
IsParent: true,
ParentID: 0,
IsDeleted: false,
Title: randSeq(rand.Intn(100)),
Text: randSeq(rand.Intn(100)),
IsSage: false,
2021-08-30 12:09:27 +03:00
Files: []File{
getFile(2, id, "https://memepedia.ru/wp-content/uploads/2018/03/ebanyy-rot-etogo-kazino.png"),
getFile(1, id, "https://memepedia.ru/wp-content/uploads/2018/03/ebanyy-rot-etogo-kazino.png"),
},
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
}
}
2021-08-31 19:48:02 +03:00
var PostsDb = []Post{}
2021-08-30 12:09:27 +03:00
func SeedMocks() {
2021-08-31 19:18:27 +03:00
rand.Seed(time.Now().UnixNano())
2021-08-31 19:48:02 +03:00
for i := 1; i < 10; i++ {
PostsDb = append(PostsDb, getPost(i))
2021-08-30 12:09:27 +03:00
}
}