From 40a6a1c3f4d08be8e91ed67ec84e13ec50a93802 Mon Sep 17 00:00:00 2001 From: Andrey Ivanov Date: Tue, 26 Jan 2021 13:37:48 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9E=D1=82=D0=BB=D0=B0=D0=B4=D0=BA=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/dataset/generator.go | 47 ++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/pkg/dataset/generator.go b/pkg/dataset/generator.go index 9699e08..50c6bbb 100644 --- a/pkg/dataset/generator.go +++ b/pkg/dataset/generator.go @@ -11,32 +11,33 @@ import ( ) type Person struct { - FirstName string - SecondName string - Password string - BirthDate time.Time - Gender string - City string - Interests []string + FirstName string + SecondName string + Password string + BirthDate time.Time + Gender string + City string + Interests []string } func NewPerson() (p Person) { rand.Seed(time.Now().UnixNano()) - p.Gender=genders[rand.Intn(len(genders))] - if p.Gender=="male" { - p.FirstName=manNames[rand.Intn(len(manNames))] - p.SecondName=secondNames[rand.Intn(len(secondNames))] + p.Gender = genders[rand.Intn(len(genders))] + if p.Gender == "male" { + p.FirstName = manNames[rand.Intn(len(manNames))] + p.SecondName = secondNames[rand.Intn(len(secondNames))] } else { - p.FirstName=womanNames[rand.Intn(len(womanNames))] - p.SecondName=secondNames[rand.Intn(len(secondNames))]+"а" + p.FirstName = womanNames[rand.Intn(len(womanNames))] + p.SecondName = secondNames[rand.Intn(len(secondNames))] + "а" } - t := make([]byte,16); rand.Read(t) - p.Password=string(t) - p.City=cities[rand.Intn(len(cities))] - for i:=0;i<(rand.Intn(4)+3);i++ { - p.Interests=append(p.Interests,interests[rand.Intn(len(interests))]) + t := make([]byte, 16) + rand.Read(t) + p.Password = string(t) + p.City = cities[rand.Intn(len(cities))] + for i := 0; i < (rand.Intn(4) + 3); i++ { + p.Interests = append(p.Interests, interests[rand.Intn(len(interests))]) } - s,_ := time.ParseDuration(strconv.Itoa(rand.Intn(700000))+"h") + s, _ := time.ParseDuration(strconv.Itoa(rand.Intn(700000)) + "h") p.BirthDate = time.Now().Add(-s) return } @@ -47,8 +48,8 @@ func FillDB(db *sql.DB, lim int) { log.Fatalf("can't exec query: %s", err.Error()) } log.Printf("Try to generate %d rows and fill the DB...", lim) - for i:=1;i