diff --git a/17-results-summary-component-go/main.go b/17-results-summary-component-go/main.go index fa9f8d2..0c70eda 100644 --- a/17-results-summary-component-go/main.go +++ b/17-results-summary-component-go/main.go @@ -14,6 +14,12 @@ var publicContent embed.FS //go:embed templates var templates embed.FS +type Category struct { + Name string + ColorHsl string + Score int +} + // starts webserver that serves html page for exercise func main() { // serves public static resources: bundled images, fonts, css @@ -24,11 +30,20 @@ func main() { io.WriteString(w, "This is temporary here, hello") }) + mySummary := [...]Category{ + {Name: "Reaction", ColorHsl: "0deg 100% 67%", Score: 80}, + {Name: "Memory", ColorHsl: "39deg 100% 56%", Score: 92}, + {Name: "Verbal", ColorHsl: "166deg 100% 37%", Score: 61}, + {Name: "Visual", ColorHsl: "234deg 85% 45%", Score: 72}, + } + // 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)) - tmpl.Execute(w, nil) + if err := tmpl.Execute(w, mySummary); err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + } }) log.Print("starting server on default :8080") diff --git a/17-results-summary-component-go/templates/summary-component.gohtml b/17-results-summary-component-go/templates/summary-component.gohtml index fd36637..d3add28 100644 --- a/17-results-summary-component-go/templates/summary-component.gohtml +++ b/17-results-summary-component-go/templates/summary-component.gohtml @@ -54,49 +54,21 @@

Summary

+ {{ range . }}
-
Reaction
+ style="--summary-item-color-var: {{ .ColorHsl }}" + > +
{{ .Name }}
- 80 - / 100 -
-
-
-
Memory
-
- 92 - / 100 -
-
-
-
Verbal
-
- 61 - / 100 -
-
-
-
Visual
-
- 72 + {{ .Score }} / 100
+ {{ end }}
Continue