diff --git a/main.go b/main.go index cbbaf18..3a1133d 100644 --- a/main.go +++ b/main.go @@ -18,13 +18,16 @@ func main() { log.Fatalln(err) } + uuidChan := make(chan string) + defer close(uuidChan) + mux.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("static/")))) mux.HandleFunc("/", server.DisplayTable(db)) mux.HandleFunc("/search/", server.DisplayResults(db)) mux.HandleFunc("/new-briefing/", server.DisplayForm(&i)) mux.HandleFunc("/add-participant/", server.AddParticipant(&i)) mux.HandleFunc("/submit-form/", server.SubmitForm(db, &i, &j)) - mux.HandleFunc("/generate-uuid/", server.GenerateUUID()) + mux.HandleFunc("/generate-uuid/", server.GenerateUUID(uuidChan)) log.Fatalln(http.ListenAndServe(":8080", mux)) } diff --git a/packages/data/questionaires.go b/packages/data/questionaires.go new file mode 100644 index 0000000..0ad59c2 --- /dev/null +++ b/packages/data/questionaires.go @@ -0,0 +1 @@ +package data diff --git a/packages/server/server.go b/packages/server/server.go index 512b654..cc22ca3 100644 --- a/packages/server/server.go +++ b/packages/server/server.go @@ -7,7 +7,6 @@ import ( "html/template" "log" "net/http" - "streifling.com/jason/sicherheitsunterweisung/packages/data" "streifling.com/jason/sicherheitsunterweisung/packages/types" ) @@ -73,11 +72,12 @@ func SubmitForm(db *data.DB, i, j *int64) http.HandlerFunc { if err != nil { _ = fmt.Errorf("SubmitForm: db.ReadAll(): %v\n", err) } + template.Must(template.ParseFiles("templates/table.html")).Execute(w, bs) } } -func GenerateUUID() http.HandlerFunc { +func GenerateUUID(ch chan<- string) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { bs := make([]byte, 4) @@ -86,6 +86,9 @@ func GenerateUUID() http.HandlerFunc { _ = fmt.Errorf("GenerateUUID: rand.Read(bs): %v\n", err) } - template.Must(template.ParseFiles("templates/form.html")).ExecuteTemplate(w, "uuid", hex.EncodeToString(bs)) + uuid := hex.EncodeToString(bs) + ch <- uuid + + template.Must(template.ParseFiles("templates/form.html")).ExecuteTemplate(w, "uuid", uuid) } }