feat: icons added via <img> by static path
This commit is contained in:
@@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"fmt"
|
||||
"html/template"
|
||||
"io"
|
||||
"log"
|
||||
@@ -18,6 +19,11 @@ type Category struct {
|
||||
Name string
|
||||
ColorHsl string
|
||||
Score int
|
||||
IconPath string
|
||||
}
|
||||
|
||||
func iconPath(categoryName string) string {
|
||||
return fmt.Sprintf("/static/public/images/icon-%s.svg", categoryName)
|
||||
}
|
||||
|
||||
// starts webserver that serves html page for exercise
|
||||
@@ -31,15 +37,19 @@ func main() {
|
||||
})
|
||||
|
||||
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},
|
||||
{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")},
|
||||
}
|
||||
|
||||
// main page with results summary
|
||||
http.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) {
|
||||
templateName := "templates/summary-component.gohtml"
|
||||
templateName := "templates/summary-component.gohtml"
|
||||
tmpl := template.Must(template.ParseFS(templates, templateName))
|
||||
if err := tmpl.Execute(w, mySummary); err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
|
||||
Reference in New Issue
Block a user