From cb6f83139f2d3db1dbcb038c82266f3e33fd7185 Mon Sep 17 00:00:00 2001 From: Jason Streifling Date: Wed, 4 Oct 2023 19:18:52 +0200 Subject: [PATCH] Numerierung der Teilnehmer durch Hilfsvariable i in main() --- main.go | 7 +++++-- templates/index.html | 18 ++++++++++-------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/main.go b/main.go index bb28da0..7de6c65 100644 --- a/main.go +++ b/main.go @@ -14,6 +14,7 @@ type Person struct { type Instructor Person type Participant struct { + id int64 Person Company string } @@ -29,13 +30,15 @@ type Briefing struct { func main() { mux := http.NewServeMux() + i := 1 mux.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("static/")))) mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { - template.Must(template.ParseFiles("templates/index.html")).Execute(w, nil) + template.Must(template.ParseFiles("templates/index.html")).Execute(w, i) }) mux.HandleFunc("/add-participant/", func(w http.ResponseWriter, r *http.Request) { - template.Must(template.ParseFiles("templates/index.html", "templates/participant.html")).ExecuteTemplate(w, "participant", nil) + i++ + template.Must(template.ParseFiles("templates/index.html", "templates/participant.html")).ExecuteTemplate(w, "participant", i) }) log.Fatalln(http.ListenAndServe(":8080", mux)) diff --git a/templates/index.html b/templates/index.html index 6189fb7..e63adc4 100644 --- a/templates/index.html +++ b/templates/index.html @@ -38,19 +38,21 @@ + -
- - +
+ + - - + + - - + +
- +