43 lines
1.0 KiB
Go
43 lines
1.0 KiB
Go
package quiz
|
|
|
|
import (
|
|
"net/http"
|
|
"time"
|
|
|
|
"forge.cadoles.com/wpetit/kouiz/internal/store"
|
|
"forge.cadoles.com/wpetit/kouiz/internal/timex"
|
|
)
|
|
|
|
type Handler struct {
|
|
mux *http.ServeMux
|
|
store *store.Store
|
|
playInterval time.Duration
|
|
playPeriod timex.PeriodType
|
|
playDelay time.Duration
|
|
}
|
|
|
|
// ServeHTTP implements http.Handler.
|
|
func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|
h.mux.ServeHTTP(w, r)
|
|
}
|
|
|
|
func NewHandler(store *store.Store, playInterval time.Duration, playPeriod timex.PeriodType, playDelay time.Duration) *Handler {
|
|
h := &Handler{
|
|
mux: http.NewServeMux(),
|
|
store: store,
|
|
playInterval: playInterval,
|
|
playPeriod: playPeriod,
|
|
playDelay: playDelay,
|
|
}
|
|
|
|
h.mux.HandleFunc("GET /", h.getQuizPage)
|
|
h.mux.HandleFunc("GET /leaderboard", h.getLeadeboardPage)
|
|
h.mux.HandleFunc("POST /select", h.handleSelectEntryForm)
|
|
h.mux.HandleFunc("POST /answer", h.handleAnswerForm)
|
|
h.mux.HandleFunc("GET /result", h.getResultPage)
|
|
|
|
return h
|
|
}
|
|
|
|
var _ http.Handler = &Handler{}
|