Отладка

actency-mysql57-replication
Andrey Ivanov 2021-01-26 13:37:48 +03:00 committed by ya@tiburon.su
parent 0f93a9cf5a
commit 40a6a1c3f4
1 changed files with 24 additions and 23 deletions

View File

@ -11,32 +11,33 @@ import (
) )
type Person struct { type Person struct {
FirstName string FirstName string
SecondName string SecondName string
Password string Password string
BirthDate time.Time BirthDate time.Time
Gender string Gender string
City string City string
Interests []string Interests []string
} }
func NewPerson() (p Person) { func NewPerson() (p Person) {
rand.Seed(time.Now().UnixNano()) rand.Seed(time.Now().UnixNano())
p.Gender=genders[rand.Intn(len(genders))] p.Gender = genders[rand.Intn(len(genders))]
if p.Gender=="male" { if p.Gender == "male" {
p.FirstName=manNames[rand.Intn(len(manNames))] p.FirstName = manNames[rand.Intn(len(manNames))]
p.SecondName=secondNames[rand.Intn(len(secondNames))] p.SecondName = secondNames[rand.Intn(len(secondNames))]
} else { } else {
p.FirstName=womanNames[rand.Intn(len(womanNames))] p.FirstName = womanNames[rand.Intn(len(womanNames))]
p.SecondName=secondNames[rand.Intn(len(secondNames))]+"а" p.SecondName = secondNames[rand.Intn(len(secondNames))] + "а"
} }
t := make([]byte,16); rand.Read(t) t := make([]byte, 16)
p.Password=string(t) rand.Read(t)
p.City=cities[rand.Intn(len(cities))] p.Password = string(t)
for i:=0;i<(rand.Intn(4)+3);i++ { p.City = cities[rand.Intn(len(cities))]
p.Interests=append(p.Interests,interests[rand.Intn(len(interests))]) 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) p.BirthDate = time.Now().Add(-s)
return return
} }
@ -47,8 +48,8 @@ func FillDB(db *sql.DB, lim int) {
log.Fatalf("can't exec query: %s", err.Error()) log.Fatalf("can't exec query: %s", err.Error())
} }
log.Printf("Try to generate %d rows and fill the DB...", lim) log.Printf("Try to generate %d rows and fill the DB...", lim)
for i:=1;i<lim;i++{ for i := 1; i < lim; i++ {
if i%100==0 { if i%100 == 0 {
log.Printf("Successfully inserted %d rows", i) log.Printf("Successfully inserted %d rows", i)
} }
p := NewPerson() p := NewPerson()
@ -62,8 +63,8 @@ func FillDB(db *sql.DB, lim int) {
p.City, p.City,
strings.Join(p.Interests, ","), strings.Join(p.Interests, ","),
); err != nil { ); err != nil {
log.Fatalf("can't insert row in DB. Inserted %d rows of %d", i, lim) log.Fatalf("can't insert row in DB. Inserted %d rows of %d: %s", i, lim, err.Error())
} }
} }
log.Println("Table USERS filled successfully") log.Println("Table USERS filled successfully")
} }