46 lines
1.3 KiB
Go
Raw Normal View History

2023-10-05 18:08:44 +02:00
package main
2023-10-04 17:13:03 +02:00
2023-10-04 17:29:22 +02:00
import (
"html/template"
2023-10-04 17:29:22 +02:00
"log"
"net/http"
"streifling.com/jason/sicherheitsunterweisung/packages/data"
"streifling.com/jason/sicherheitsunterweisung/packages/server"
2023-10-04 17:29:22 +02:00
)
func addUUIDs(uc *chan string, uuids *[]string) {
for uuid := range *uc {
(*uuids) = append(*uuids, uuid)
}
}
2023-10-04 17:29:22 +02:00
func main() {
var i, j int64
uuids := make([]string, 0)
i, j = 1, 1
mux := http.NewServeMux()
db, err := data.OpenDB("sicherheitsunterweisung")
if err != nil {
log.Fatalln(err)
}
uuidChan := make(chan string)
defer close(uuidChan)
go addUUIDs(&uuidChan, &uuids)
mux.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("static/"))))
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
template.Must(template.ParseFiles("templates/index.html", "templates/login.html")).Execute(w, nil)
})
mux.HandleFunc("/search/", server.DisplayResults(db))
mux.HandleFunc("/new-briefing/", server.DisplayForm(&i))
mux.HandleFunc("/add-participant/", server.AddParticipant(&i))
2023-10-10 18:43:48 +02:00
mux.HandleFunc("/submit-form/", server.SubmitForm(db, &i, &j))
mux.HandleFunc("/generate-uuid/", server.GenerateUUID(uuidChan))
mux.HandleFunc("/internal-login/", server.DisplayTable(db))
mux.HandleFunc("/external-login/", server.DisplayQuestionsIfOK(&uuids))
2023-10-04 17:29:22 +02:00
log.Fatalln(http.ListenAndServe(":8080", mux))
}