-
Notifications
You must be signed in to change notification settings - Fork 1
/
load.go
52 lines (47 loc) · 1014 Bytes
/
load.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package usanames
import (
"bytes"
_ "embed"
"encoding/csv"
)
//go:embed data/first-names/yob2021.txt
var firstNames2021 []byte
//go:embed data/last-names/Names_2010Census.csv
var lastNames2010 []byte
var FirstNames []string
var LastNames []string
func init() {
firstNamesReader := csv.NewReader(bytes.NewReader(firstNames2021))
firstNamesReader.ReuseRecord = true
for {
records, err := firstNamesReader.Read()
if err != nil {
break
}
if len(records) == 0 {
break
}
FirstNames = append(FirstNames, records[0])
}
lastNamesReader := csv.NewReader(bytes.NewReader(lastNames2010))
lastNamesReader.ReuseRecord = true
gotFirstRow := false
for {
records, err := lastNamesReader.Read()
if err != nil {
break
}
if len(records) == 0 {
break
}
// The first row is a header; ignore it.
if !gotFirstRow {
gotFirstRow = true
continue
}
// The last records is a catch-all; ignore it.
if records[1] != "0" {
LastNames = append(LastNames, records[0])
}
}
}