From 2409f18afa9d36fc4050db4b3126589f293fe4f5 Mon Sep 17 00:00:00 2001 From: Yanislav Igonin Date: Tue, 31 Aug 2021 19:18:27 +0300 Subject: [PATCH] feat: random text on mocks --- repositories/mocks.go | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/repositories/mocks.go b/repositories/mocks.go index 27662fd..4a178bd 100644 --- a/repositories/mocks.go +++ b/repositories/mocks.go @@ -1,6 +1,19 @@ 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 { return File{ @@ -17,8 +30,8 @@ func getPost(id, threadID int) Post { return Post{ ID: id, ThreadID: threadID, - Title: "Basic Title", - Text: "Basic Text", + Title: randSeq(rand.Intn(100)), + Text: randSeq(rand.Intn(100)), IsSage: false, Files: []File{ 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{} func SeedMocks() { - for i := 1; i < 10; i++ { + rand.Seed(time.Now().UnixNano()) + + for i := 1; i < 100; i++ { ThreadsDb = append(ThreadsDb, getThread(i)) } }