Verschiedene Typen in package types ausgelagert und Channels zum asynchronen Datentransport eingesetzt
This commit is contained in:
@ -5,30 +5,9 @@ import (
|
||||
"html/template"
|
||||
"log"
|
||||
"net/http"
|
||||
"streifling.com/jason/sicherheitsunterweisung/types"
|
||||
)
|
||||
|
||||
type Person struct {
|
||||
FirstName string
|
||||
LastName string
|
||||
}
|
||||
|
||||
type Instructor Person
|
||||
|
||||
type Participant struct {
|
||||
ID int64
|
||||
Person
|
||||
Company string
|
||||
}
|
||||
|
||||
type Briefing struct {
|
||||
Instructor
|
||||
Date string
|
||||
Time string
|
||||
State string
|
||||
Location string
|
||||
Participants []Participant
|
||||
}
|
||||
|
||||
func DisplayForm(i *int64) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
template.Must(template.ParseFiles("templates/index.html")).Execute(w, i)
|
||||
@ -42,8 +21,10 @@ func AddParticipant(i *int64) http.HandlerFunc {
|
||||
}
|
||||
}
|
||||
|
||||
func SubmitForm(b *Briefing, i, j *int64) http.HandlerFunc {
|
||||
func SubmitForm(ch chan<- *types.Briefing, i, j *int64) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var b types.Briefing
|
||||
|
||||
b.FirstName = r.PostFormValue("instructor-first")
|
||||
b.LastName = r.PostFormValue("instructor-last")
|
||||
b.Date = r.PostFormValue("date")
|
||||
@ -52,9 +33,9 @@ func SubmitForm(b *Briefing, i, j *int64) http.HandlerFunc {
|
||||
b.Location = r.PostFormValue("location")
|
||||
|
||||
for ; *j <= *i; *j++ {
|
||||
b.Participants = append(b.Participants, Participant{
|
||||
b.Participants = append(b.Participants, types.Participant{
|
||||
ID: *j,
|
||||
Person: Person{
|
||||
Person: types.Person{
|
||||
FirstName: r.PostFormValue("participant-first-" + fmt.Sprint(*j)),
|
||||
LastName: r.PostFormValue(("participant-last-" + fmt.Sprint(*j))),
|
||||
},
|
||||
@ -62,6 +43,7 @@ func SubmitForm(b *Briefing, i, j *int64) http.HandlerFunc {
|
||||
})
|
||||
}
|
||||
|
||||
log.Println("Received ", *b)
|
||||
log.Println(b)
|
||||
ch <- &b
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user