diff --git a/17-results-summary-component-go/main.go b/17-results-summary-component-go/main.go index ac7efab..6e98b50 100644 --- a/17-results-summary-component-go/main.go +++ b/17-results-summary-component-go/main.go @@ -26,6 +26,12 @@ func iconPath(categoryName string) string { return fmt.Sprintf("/static/public/images/icon-%s.svg", categoryName) } +type ResultsSummaryData struct { + Categories []Category + TotalScore int + UpperPercent int +} + // starts webserver that serves html page for exercise func main() { // serves public static resources: bundled images, fonts, css @@ -36,22 +42,26 @@ func main() { io.WriteString(w, "This is temporary here, hello") }) - mySummary := [...]Category{ - {Name: "Reaction", ColorHsl: "0deg 100% 67%", - Score: 80, IconPath: iconPath("reaction")}, - {Name: "Memory", ColorHsl: "39deg 100% 56%", - Score: 92, IconPath: iconPath("memory")}, - {Name: "Verbal", ColorHsl: "166deg 100% 37%", - Score: 61, IconPath: iconPath("verbal")}, - {Name: "Visual", ColorHsl: "234deg 85% 45%", - Score: 72, IconPath: iconPath("visual")}, + resultsData := ResultsSummaryData{ + Categories: []Category{ + {Name: "Reaction", ColorHsl: "0deg 100% 67%", + Score: 80, IconPath: iconPath("reaction")}, + {Name: "Memory", ColorHsl: "39deg 100% 56%", + Score: 92, IconPath: iconPath("memory")}, + {Name: "Verbal", ColorHsl: "166deg 100% 37%", + Score: 61, IconPath: iconPath("verbal")}, + {Name: "Visual", ColorHsl: "234deg 85% 45%", + Score: 72, IconPath: iconPath("visual")}, + }, + TotalScore: 76, + UpperPercent: 65, } // main page with results summary http.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) { templateName := "templates/summary-component.gohtml" tmpl := template.Must(template.ParseFS(templates, templateName)) - if err := tmpl.Execute(w, mySummary); err != nil { + if err := tmpl.Execute(w, resultsData); err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) } }) diff --git a/17-results-summary-component-go/public/out.css b/17-results-summary-component-go/public/out.css index 07567d6..1811410 100644 --- a/17-results-summary-component-go/public/out.css +++ b/17-results-summary-component-go/public/out.css @@ -646,6 +646,10 @@ video { --tw-gradient-stops: var(--tw-gradient-from), var(--tw-gradient-to); } +.from-50\% { + --tw-gradient-from-position: 50%; +} + .to-light-slate-blue { --tw-gradient-to: hsl(252, 100%, 67%) var(--tw-gradient-to-position); } diff --git a/17-results-summary-component-go/templates/summary-component.gohtml b/17-results-summary-component-go/templates/summary-component.gohtml index f43bf08..bbb46f5 100644 --- a/17-results-summary-component-go/templates/summary-component.gohtml +++ b/17-results-summary-component-go/templates/summary-component.gohtml @@ -38,7 +38,7 @@ >

Your Result @@ -46,13 +46,13 @@
- 76 + {{ .TotalScore }} of 100

Great

- You scored higher than 65% of the people who have taken these + You scored higher than {{ .UpperPercent }}% of the people who have taken these tests.

@@ -64,7 +64,7 @@ >

Summary

- {{ range . }} + {{ range .Categories }}