You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1.4 KiB

Create an application that uses the brianvoe/gofakeit package to generate random data for the following type:

type User struct {
	UID       string `json:"uid"`
	FirstName string `json:"first_name"`
	LastName  string `json:"last_name"`
	Status    string `json:"status"`
	ExamID string `json:"exam_id"`
}

The application should read in a config file called config.json (and call log.Fatalf on any obvious error) of the following type:

type Config struct {
    NumberOfUsers int `json:"number_of_users"`
    PercentStatus map[string]int `json:"percent_status"`
}

Status should be a member of statuses, which is string[]{"JD", "LLM", "MCL", "PHD", "SJD", "MLS", "SPEC", "MNR", "CERT"}

Check that all the int values in PercentStatus total 100. Use log.Fatalf to end early on an error if they don't.

Generate a []User equal in length to the value of Config's NumberOfUsers member meeting the following requirements:

  1. ExamID should be a unique random string of 4 digits
  2. UID should be a unique random string of 10 digits
  3. members of the []User list should have status in proportion to the entry for status in the PercentStatus config variable
  4. FirstName should be the result of brianvoe/gofaker FirstName
  5. LastName should be the result of brianvoe/gofaker LastName

Output the results to a file called "users.csv". This should be a csv file with the fields in UID, FirstName, LastName, Status, ExameID order.