feat: random text on mocks

This commit is contained in:
Yanislav Igonin 2021-08-31 19:18:27 +03:00
parent 51fd582a31
commit 2409f18afa

View File

@ -1,6 +1,19 @@
package repositories package repositories
import "time" 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)
}
func getFile(id, postId int, name string) File { func getFile(id, postId int, name string) File {
return File{ return File{
@ -17,8 +30,8 @@ func getPost(id, threadID int) Post {
return Post{ return Post{
ID: id, ID: id,
ThreadID: threadID, ThreadID: threadID,
Title: "Basic Title", Title: randSeq(rand.Intn(100)),
Text: "Basic Text", Text: randSeq(rand.Intn(100)),
IsSage: false, IsSage: false,
Files: []File{ Files: []File{
getFile(2, id, "https://memepedia.ru/wp-content/uploads/2018/03/ebanyy-rot-etogo-kazino.png"), getFile(2, id, "https://memepedia.ru/wp-content/uploads/2018/03/ebanyy-rot-etogo-kazino.png"),
@ -43,7 +56,9 @@ func getThread(id int) Thread {
var ThreadsDb = []Thread{} var ThreadsDb = []Thread{}
func SeedMocks() { func SeedMocks() {
for i := 1; i < 10; i++ { rand.Seed(time.Now().UnixNano())
for i := 1; i < 100; i++ {
ThreadsDb = append(ThreadsDb, getThread(i)) ThreadsDb = append(ThreadsDb, getThread(i))
} }
} }