Verwendung von Pointern, um Vermischung der Pakete zu vermeiden

This commit is contained in:
2023-10-05 18:27:21 +02:00
parent 1c39b1e471
commit fcb509c9fe
2 changed files with 20 additions and 17 deletions

View File

@ -3,6 +3,7 @@ package server
import (
"fmt"
"html/template"
"log"
"net/http"
)
@ -28,37 +29,39 @@ type Briefing struct {
Participants []Participant
}
func DisplayForm(i int64) http.HandlerFunc {
func DisplayForm(i *int64) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
template.Must(template.ParseFiles("templates/index.html")).Execute(w, i)
}
}
func AddParticipant(i int64) http.HandlerFunc {
func AddParticipant(i *int64) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
i++
*i++
template.Must(template.ParseFiles("templates/index.html", "templates/participant.html")).ExecuteTemplate(w, "participant", i)
}
}
func SubmitForm(b Briefing, i, j int64) http.HandlerFunc {
func SubmitForm(b *Briefing, i, j *int64) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
b.Instructor.FirstName = r.PostFormValue("instructor-first")
b.Instructor.LastName = r.PostFormValue("instructor-last")
b.FirstName = r.PostFormValue("instructor-first")
b.LastName = r.PostFormValue("instructor-last")
b.Date = r.PostFormValue("date")
b.Time = r.PostFormValue("time")
b.State = r.PostFormValue("state")
b.Location = r.PostFormValue("location")
for ; j <= i; j++ {
for ; *j <= *i; *j++ {
b.Participants = append(b.Participants, Participant{
ID: j,
ID: *j,
Person: Person{
FirstName: r.PostFormValue("participant-first-" + fmt.Sprint(j)),
LastName: r.PostFormValue(("participant-last-" + fmt.Sprint(j))),
FirstName: r.PostFormValue("participant-first-" + fmt.Sprint(*j)),
LastName: r.PostFormValue(("participant-last-" + fmt.Sprint(*j))),
},
Company: r.PostFormValue(("participant-company-" + fmt.Sprint(j))),
Company: r.PostFormValue(("participant-company-" + fmt.Sprint(*j))),
})
}
log.Println("Received ", *b)
}
}