-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
43 lines (36 loc) · 1.23 KB
/
main.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
package main
import (
"findStudent/src/extract"
"findStudent/src/utils"
"fmt"
"strings"
)
func main() {
var allGraduates []utils.Student
careers := utils.GetCareers()
studentChan := make(chan []utils.Student)
var firstName, lastName string
fmt.Println("Do not use accents please!")
firstName = utils.ReadUserInput("Enter the first name of the student you're looking for: ")
lastName = utils.ReadUserInput("Enter the last name of the student you're looking for: ")
fmt.Println()
for careerName, careerCode := range careers {
go extract.GetStudents(careerCode, careerName, studentChan)
}
for i := 0; i < len(careers); i++ {
students := <-studentChan
allGraduates = append(allGraduates, students...)
}
fmt.Printf("\nThese are the names most similar to \"%s %s\":\n\n", firstName, lastName)
hasFound := false
for _, graduate := range allGraduates {
if utils.MatchNames(strings.ToLower(graduate.Name), firstName, lastName) {
// strings.Title is deprecated, but it's harmless in this context
fmt.Printf("%s: Graduated from %s in %s\n", strings.Title(graduate.Name), graduate.Career, graduate.Year)
hasFound = true
}
}
if !hasFound {
fmt.Printf("No students whose name starts with %s were found.\n", firstName)
}
}