mirror of
https://github.com/airlabspl/uptimemonitor.git
synced 2025-08-15 04:39:15 +02:00
32 lines
619 B
Go
32 lines
619 B
Go
package handler
|
|
|
|
import (
|
|
"html/template"
|
|
"net/http"
|
|
"uptimemonitor"
|
|
"uptimemonitor/html"
|
|
"uptimemonitor/pkg/version"
|
|
)
|
|
|
|
func (h *Handler) HomePage() http.HandlerFunc {
|
|
tmpl := template.Must(template.ParseFS(html.FS, "layout.html", "app.html", "home.html"))
|
|
|
|
type data struct {
|
|
Version string
|
|
User uptimemonitor.User
|
|
}
|
|
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
count := h.Store.CountMonitors(r.Context())
|
|
if count == 0 {
|
|
http.Redirect(w, r, "/new", http.StatusSeeOther)
|
|
return
|
|
}
|
|
|
|
tmpl.Execute(w, data{
|
|
Version: version.Version,
|
|
User: getUserFromRequest(r),
|
|
})
|
|
}
|
|
}
|