46 lines
1.3 KiB
Go
46 lines
1.3 KiB
Go
package main
|
|
|
|
import (
|
|
"html/template"
|
|
"log"
|
|
"net/http"
|
|
"streifling.com/jason/sicherheitsunterweisung/packages/data"
|
|
"streifling.com/jason/sicherheitsunterweisung/packages/server"
|
|
)
|
|
|
|
func addUUIDs(uc *chan string, uuids *[]string) {
|
|
for uuid := range *uc {
|
|
(*uuids) = append(*uuids, uuid)
|
|
}
|
|
}
|
|
|
|
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))
|
|
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))
|
|
|
|
log.Fatalln(http.ListenAndServe(":8080", mux))
|
|
}
|