2023-10-04 17:13:03 +02:00
|
|
|
package main
|
|
|
|
|
2023-10-04 17:29:22 +02:00
|
|
|
import (
|
2023-10-05 16:50:23 +02:00
|
|
|
"fmt"
|
2023-10-04 17:29:22 +02:00
|
|
|
"html/template"
|
|
|
|
"log"
|
|
|
|
"net/http"
|
|
|
|
)
|
|
|
|
|
2023-10-04 17:41:22 +02:00
|
|
|
type Person struct {
|
|
|
|
FirstName string
|
|
|
|
LastName string
|
|
|
|
}
|
|
|
|
|
|
|
|
type Instructor Person
|
|
|
|
|
|
|
|
type Participant struct {
|
2023-10-05 16:50:23 +02:00
|
|
|
ID int64
|
2023-10-04 17:41:22 +02:00
|
|
|
Person
|
|
|
|
Company string
|
|
|
|
}
|
|
|
|
|
|
|
|
type Briefing struct {
|
|
|
|
Instructor
|
|
|
|
Date string
|
|
|
|
Time string
|
|
|
|
State string
|
|
|
|
Location string
|
|
|
|
Participants []Participant
|
|
|
|
}
|
|
|
|
|
2023-10-04 17:29:22 +02:00
|
|
|
func main() {
|
2023-10-05 16:50:23 +02:00
|
|
|
var i, j int64
|
|
|
|
var b Briefing
|
|
|
|
|
2023-10-04 17:29:22 +02:00
|
|
|
mux := http.NewServeMux()
|
2023-10-05 16:50:23 +02:00
|
|
|
i, j = 1, 1
|
2023-10-04 18:55:48 +02:00
|
|
|
|
|
|
|
mux.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("static/"))))
|
2023-10-04 17:29:22 +02:00
|
|
|
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
2023-10-04 19:18:52 +02:00
|
|
|
template.Must(template.ParseFiles("templates/index.html")).Execute(w, i)
|
2023-10-04 17:29:22 +02:00
|
|
|
})
|
2023-10-04 18:55:48 +02:00
|
|
|
mux.HandleFunc("/add-participant/", func(w http.ResponseWriter, r *http.Request) {
|
2023-10-04 19:18:52 +02:00
|
|
|
i++
|
2023-10-05 16:50:23 +02:00
|
|
|
j = i
|
2023-10-04 19:18:52 +02:00
|
|
|
template.Must(template.ParseFiles("templates/index.html", "templates/participant.html")).ExecuteTemplate(w, "participant", i)
|
2023-10-04 18:55:48 +02:00
|
|
|
})
|
2023-10-05 16:50:23 +02:00
|
|
|
mux.HandleFunc("/submit/", func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
b.Instructor.FirstName = r.PostFormValue("instructor-first")
|
|
|
|
b.Instructor.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++ {
|
|
|
|
b.Participants = append(b.Participants, Participant{
|
|
|
|
ID: j,
|
|
|
|
Person: Person{
|
|
|
|
FirstName: r.PostFormValue("participant-first-" + fmt.Sprint(j)),
|
|
|
|
LastName: r.PostFormValue(("participant-last-" + fmt.Sprint(j))),
|
|
|
|
},
|
|
|
|
Company: r.PostFormValue(("participant-company-" + fmt.Sprint(j))),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
2023-10-04 17:29:22 +02:00
|
|
|
|
|
|
|
log.Fatalln(http.ListenAndServe(":8080", mux))
|
|
|
|
}
|