Versuch, eine übersichtlichere Struktur einzuführen
This commit is contained in:
49
packages/server/server.go
Normal file
49
packages/server/server.go
Normal file
@ -0,0 +1,49 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"html/template"
|
||||
"log"
|
||||
"net/http"
|
||||
"streifling.com/jason/sicherheitsunterweisung/packages/types"
|
||||
)
|
||||
|
||||
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 {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
*i++
|
||||
template.Must(template.ParseFiles("templates/index.html", "templates/participant.html")).ExecuteTemplate(w, "participant", i)
|
||||
}
|
||||
}
|
||||
|
||||
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")
|
||||
b.Time = r.PostFormValue("time")
|
||||
b.State = r.PostFormValue("state")
|
||||
b.Location = r.PostFormValue("location")
|
||||
|
||||
for ; *j <= *i; *j++ {
|
||||
b.Participants = append(b.Participants, types.Participant{
|
||||
ID: *j,
|
||||
Person: types.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))),
|
||||
})
|
||||
}
|
||||
|
||||
log.Println(b)
|
||||
ch <- &b
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user