Code in Pakete aufgeteilt
This commit is contained in:
64
server/server.go
Normal file
64
server/server.go
Normal file
@ -0,0 +1,64 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"html/template"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
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(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.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))),
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user