43 lines
1.1 KiB
Go
43 lines
1.1 KiB
Go
package main
|
|
|
|
import (
|
|
"log"
|
|
"net/http"
|
|
"synlotto-website/handlers"
|
|
"synlotto-website/helpers"
|
|
"synlotto-website/middleware"
|
|
"synlotto-website/models"
|
|
"synlotto-website/storage"
|
|
|
|
"github.com/gorilla/csrf"
|
|
)
|
|
|
|
func main() {
|
|
db := storage.InitDB("synlotto.db")
|
|
models.SetDB(db)
|
|
|
|
csrfMiddleware := csrf.Protect(
|
|
[]byte("abcdefghijklmnopqrstuvwx12345678"), // TodO: Make Global
|
|
csrf.Secure(true),
|
|
csrf.Path("/"),
|
|
)
|
|
|
|
mux := http.NewServeMux()
|
|
|
|
mux.HandleFunc("/", handlers.Home(db))
|
|
mux.HandleFunc("/new", handlers.NewDraw) // ToDo: needs to be wrapped in admin auth
|
|
mux.HandleFunc("/submit", handlers.Submit)
|
|
|
|
// Result pages
|
|
mux.HandleFunc("/results/thunderball", handlers.ResultsThunderball(db))
|
|
|
|
// Account Pages
|
|
mux.HandleFunc("/login", middleware.Auth(false)(handlers.Login))
|
|
mux.HandleFunc("/logout", handlers.Logout)
|
|
mux.HandleFunc("/signup", middleware.Auth(false)(handlers.Signup))
|
|
mux.HandleFunc("/account/tickets/add_ticket", middleware.Auth(true)(handlers.AddTicket(db)))
|
|
|
|
log.Println("🌐 Running on http://localhost:8080")
|
|
http.ListenAndServe(":8080", helpers.RateLimit(csrfMiddleware(mux)))
|
|
}
|