@ -7,6 +7,7 @@ import (
"log"
"math/rand"
"os"
"strings"
"github.com/brianvoe/gofakeit/v6"
)
@ -490,6 +491,9 @@ type User struct {
LastName string ` json:"last_name" `
Status string ` json:"status" `
ExamID string ` json:"exam_id" `
Username string ` json:"username" `
APIKey string ` json:"api_key" `
PasswordHash string ` json:"password_hash" `
}
type Section struct {
@ -531,6 +535,8 @@ func GenerateUserData(config Config) []User {
LastName : gofakeit . LastName ( ) ,
Status : weightedStatuses [ rand . Intn ( len ( weightedStatuses ) ) ] ,
ExamID : examIDs [ i ] ,
APIKey : strings . ReplaceAll ( gofakeit . UUID ( ) , "-" , "" ) ,
PasswordHash : gofakeit . Password ( true , true , true , true , false , 16 ) ,
}
}
@ -547,11 +553,11 @@ func SaveGeneratedUsers(users []User) {
defer f . Close ( )
w := csv . NewWriter ( f )
if err := w . Write ( [ ] string { "uid" , "first_name" , "last_name" , "status" , "exam_id" }) ; err != nil {
if err := w . Write ( [ ] string { "uid" , "first_name" , "last_name" , "status" , "exam_id" , "api_key" , "password_hash" }) ; err != nil {
log . Fatalf ( "failed to write csv header: %v" , err )
}
for _ , u := range users {
if err := w . Write ( [ ] string { u . UID , u . FirstName , u . LastName , u . Status , u . ExamID }) ; err != nil {
if err := w . Write ( [ ] string { u . UID , u . FirstName , u . LastName , u . Status , u . ExamID , u . APIKey , u . PasswordHash }) ; err != nil {
log . Fatalf ( "failed to write csv row: %v" , err )
}
}