func (ss *SubmitServer) Listen() { http.HandleFunc("/submit", ss.securePage(ss.submitJob)) http.HandleFunc("/stop", ss.securePage(ss.stopJob)) http.HandleFunc("/start", ss.securePage(ss.startJob)) http.HandleFunc("/Jobs", ss.securePage(ss.listJobs)) http.HandleFunc("/JobStatus", ss.securePage(ss.jobStatus)) http.HandleFunc("/DeleteJob", ss.securePage(ss.deleteJob)) http.HandleFunc("/GetJobResult", ss.securePage(ss.getJobResult)) http.HandleFunc("/CreateJob", ss.securePage(ss.createJob)) http.HandleFunc("/Help", ss.securePage(ss.help)) http.HandleFunc("/About", ss.securePage(ss.about)) http.HandleFunc("/Admin", ss.securePage(ss.admin)) http.HandleFunc("/Logout", ss.securePage(ss.logoutUser)) http.HandleFunc("/Observe/Get/", ss.securePage(ss.observe)) http.HandleFunc("/Observe/New/", ss.securePage(ss.addObserver)) http.HandleFunc("/TryLogin", ss.loginUser) http.HandleFunc("/TryRegister", ss.newUser) http.Handle("/", http.StripPrefix("/", http.FileServer(http.Dir("resources/files")))) log.Println("Starting SubmitServer") defer reaper.Quit(reaper.Run(ss.boltDB, reaper.Options{})) err := http.ListenAndServe(ss.Address, nil) if err != nil { panic(err) } }
func Setup() { // setup sessions sessionDB, err := bolt.Open("./sessions.db", 0666, nil) if err != nil { panic(err) } defer sessionDB.Close() defer reaper.Quit(reaper.Run(sessionDB, reaper.Options{})) // setup routes r := mux.NewRouter() sr := r.PathPrefix("/api/v1").Subrouter() domains.Setup(sr) whois.Setup(sr) records.Setup(sr) watchers.Setup(sr) auth.Setup(sr) notifications.Setup(sr) // setup authoriser authoriser := auth.New(sessionDB) h := authoriser(r) http.ListenAndServe(":8080", h) }