mirror of
https://github.com/airlabspl/uptimemonitor.git
synced 2025-08-15 04:39:15 +02:00
initial commit
This commit is contained in:
28
handler/home_handler.go
Normal file
28
handler/home_handler.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"html/template"
|
||||
"net/http"
|
||||
"uptimemonitor"
|
||||
"uptimemonitor/html"
|
||||
)
|
||||
|
||||
func (h *Handler) HomePage() http.HandlerFunc {
|
||||
tmpl := template.Must(template.ParseFS(html.FS, "layout.html", "app.html", "home.html"))
|
||||
|
||||
type data struct {
|
||||
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{
|
||||
User: getUserFromRequest(r),
|
||||
})
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user