36 lines
842 B
Go
36 lines
842 B
Go
package main
|
|
|
|
import (
|
|
api "code.dlmw.ch/dlmw/qv/internal"
|
|
"code.dlmw.ch/dlmw/qv/internal/models"
|
|
"code.dlmw.ch/dlmw/qv/ui"
|
|
"github.com/justinas/alice"
|
|
"log/slog"
|
|
"net/http"
|
|
)
|
|
|
|
type application struct {
|
|
logger *slog.Logger
|
|
elections models.ElectionModelInterface
|
|
voters models.VoterModelInterface
|
|
votes models.VoteModelInterface
|
|
}
|
|
|
|
func (app *application) routes() http.Handler {
|
|
mux := http.NewServeMux()
|
|
|
|
cached := alice.New(app.cacheStatic)
|
|
mux.Handle("GET /static/", cached.Then(http.FileServerFS(ui.Files)))
|
|
|
|
mux.HandleFunc("GET /election/create", app.createElectionPage)
|
|
|
|
api.HandlerWithOptions(app, api.StdHTTPServerOptions{
|
|
BaseRouter: mux,
|
|
BaseURL: "/api",
|
|
ErrorHandlerFunc: app.badRequestError,
|
|
})
|
|
|
|
standard := alice.New(app.recoverPanic, app.logRequest)
|
|
return standard.Then(mux)
|
|
}
|