Generierte UUID in einen asynchronen Speicher schreiben
This commit is contained in:
parent
616df72041
commit
608879d008
5
main.go
5
main.go
@ -18,13 +18,16 @@ func main() {
|
|||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uuidChan := make(chan string)
|
||||||
|
defer close(uuidChan)
|
||||||
|
|
||||||
mux.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("static/"))))
|
mux.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("static/"))))
|
||||||
mux.HandleFunc("/", server.DisplayTable(db))
|
mux.HandleFunc("/", server.DisplayTable(db))
|
||||||
mux.HandleFunc("/search/", server.DisplayResults(db))
|
mux.HandleFunc("/search/", server.DisplayResults(db))
|
||||||
mux.HandleFunc("/new-briefing/", server.DisplayForm(&i))
|
mux.HandleFunc("/new-briefing/", server.DisplayForm(&i))
|
||||||
mux.HandleFunc("/add-participant/", server.AddParticipant(&i))
|
mux.HandleFunc("/add-participant/", server.AddParticipant(&i))
|
||||||
mux.HandleFunc("/submit-form/", server.SubmitForm(db, &i, &j))
|
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))
|
log.Fatalln(http.ListenAndServe(":8080", mux))
|
||||||
}
|
}
|
||||||
|
1
packages/data/questionaires.go
Normal file
1
packages/data/questionaires.go
Normal file
@ -0,0 +1 @@
|
|||||||
|
package data
|
@ -7,7 +7,6 @@ import (
|
|||||||
"html/template"
|
"html/template"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"streifling.com/jason/sicherheitsunterweisung/packages/data"
|
"streifling.com/jason/sicherheitsunterweisung/packages/data"
|
||||||
"streifling.com/jason/sicherheitsunterweisung/packages/types"
|
"streifling.com/jason/sicherheitsunterweisung/packages/types"
|
||||||
)
|
)
|
||||||
@ -73,11 +72,12 @@ func SubmitForm(db *data.DB, i, j *int64) http.HandlerFunc {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
_ = fmt.Errorf("SubmitForm: db.ReadAll(): %v\n", err)
|
_ = fmt.Errorf("SubmitForm: db.ReadAll(): %v\n", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
template.Must(template.ParseFiles("templates/table.html")).Execute(w, bs)
|
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) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
bs := make([]byte, 4)
|
bs := make([]byte, 4)
|
||||||
|
|
||||||
@ -86,6 +86,9 @@ func GenerateUUID() http.HandlerFunc {
|
|||||||
_ = fmt.Errorf("GenerateUUID: rand.Read(bs): %v\n", err)
|
_ = 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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user