Sessionhandler eingefügt und Code entsprechend umgestellt
This commit is contained in:
		
							
								
								
									
										29
									
								
								main.go
									
									
									
									
									
								
							
							
						
						
									
										29
									
								
								main.go
									
									
									
									
									
								
							@@ -1,33 +1,44 @@
 | 
			
		||||
package main
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"html/template"
 | 
			
		||||
	"log"
 | 
			
		||||
	"net/http"
 | 
			
		||||
 | 
			
		||||
	"streifling.com/jason/sicherheitsunterweisung/packages/data"
 | 
			
		||||
	"streifling.com/jason/sicherheitsunterweisung/packages/db"
 | 
			
		||||
	"streifling.com/jason/sicherheitsunterweisung/packages/server"
 | 
			
		||||
	"streifling.com/jason/sicherheitsunterweisung/packages/types"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func main() {
 | 
			
		||||
	logins := make([]string, 0)
 | 
			
		||||
func handleSessions(mux *http.ServeMux, db *db.DB, ss []*types.Session, cs <-chan *types.Session) {
 | 
			
		||||
	for session := range cs {
 | 
			
		||||
		ss = append(ss, session)
 | 
			
		||||
		mux.HandleFunc("/add-participant-"+fmt.Sprint(session.ID)+"/", server.AddParticipant(session))
 | 
			
		||||
		mux.HandleFunc("/submit-form-"+fmt.Sprint(session.ID)+"/", server.SubmitBriefingForm(session, db))
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
	db, err := data.OpenDB("sicherheitsunterweisung")
 | 
			
		||||
func main() {
 | 
			
		||||
	db, err := db.Open("sicherheitsunterweisung")
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		log.Fatalln(err)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	sessions := make([]*types.Session, 0)
 | 
			
		||||
	sessionChan := make(chan *types.Session)
 | 
			
		||||
 | 
			
		||||
	mux := http.NewServeMux()
 | 
			
		||||
	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.DisplaySearchResults(db))
 | 
			
		||||
	mux.HandleFunc("/new-briefing/", server.DisplayInstructorForm())
 | 
			
		||||
	mux.HandleFunc("/add-participant/", server.AddParticipant(&logins))
 | 
			
		||||
	mux.HandleFunc("/submit-form/", server.SubmitBriefingForm(db, &logins))
 | 
			
		||||
	mux.HandleFunc("/internal-login/", server.DisplayTable(db))
 | 
			
		||||
	mux.HandleFunc("/external-login/", server.DisplayParticipantForm(&logins))
 | 
			
		||||
	mux.HandleFunc("/external-login/", server.DisplayParticipantForm(sessions))
 | 
			
		||||
	mux.HandleFunc("/search/", server.DisplaySearchResults(db))
 | 
			
		||||
	mux.HandleFunc("/new-briefing/", server.DisplayInstructorForm(sessionChan))
 | 
			
		||||
 | 
			
		||||
	go handleSessions(mux, db, sessions, sessionChan)
 | 
			
		||||
 | 
			
		||||
	log.Fatalln(http.ListenAndServe(":8080", mux))
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user