Files
website/main.go
2025-03-25 21:39:48 +00:00

43 lines
1.2 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("32-byte-long-auth-key-here"), // 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)
mux.HandleFunc("/ticket", handlers.NewTicket(db))
mux.HandleFunc("/tickets", middleware.Auth(true)(handlers.ListTickets(db)))
mux.HandleFunc("/submit-ticket", helpers.AuthMiddleware(handlers.SubmitTicket(db)))
mux.HandleFunc("/login", middleware.Auth(false)(handlers.Login))
mux.HandleFunc("/logout", handlers.Logout)
mux.HandleFunc("/signup", middleware.Auth(false)(handlers.Signup))
// Result pages
mux.HandleFunc("/results/thunderball", handlers.ResultsThunderball(db))
log.Println("🌐 Running on http://localhost:8080")
http.ListenAndServe(":8080", helpers.RateLimit(csrfMiddleware(mux)))
}