2024-02-11 19:28:00 +00:00
|
|
|
package handlers
|
2024-02-10 11:59:58 +00:00
|
|
|
|
|
|
|
import (
|
2024-02-12 13:20:38 +00:00
|
|
|
"math/rand"
|
2024-02-10 11:59:58 +00:00
|
|
|
"net/http"
|
|
|
|
|
2024-02-12 10:22:14 +00:00
|
|
|
"code.tjo.space/mentos1386/zdravko/web/templates/components"
|
2024-02-20 10:24:04 +00:00
|
|
|
"github.com/labstack/echo/v4"
|
2024-02-10 11:59:58 +00:00
|
|
|
)
|
|
|
|
|
2024-02-12 13:20:38 +00:00
|
|
|
type IndexData struct {
|
|
|
|
*components.Base
|
|
|
|
HealthChecks []*HealthCheck
|
|
|
|
}
|
|
|
|
|
|
|
|
type HealthCheck struct {
|
|
|
|
Domain string
|
|
|
|
Healthy bool
|
|
|
|
Uptime string
|
|
|
|
History []bool
|
|
|
|
}
|
|
|
|
|
|
|
|
func newMockHealthCheck(domain string) *HealthCheck {
|
|
|
|
randBool := func() bool {
|
|
|
|
return rand.Intn(2) == 1
|
|
|
|
}
|
|
|
|
|
|
|
|
var history []bool
|
|
|
|
for i := 0; i < 90; i++ {
|
|
|
|
history = append(history, randBool())
|
|
|
|
}
|
|
|
|
|
|
|
|
return &HealthCheck{
|
|
|
|
Domain: domain,
|
|
|
|
Healthy: randBool(),
|
|
|
|
Uptime: "100",
|
|
|
|
History: history,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-20 10:24:04 +00:00
|
|
|
func (h *BaseHandler) Index(c echo.Context) error {
|
|
|
|
return c.Render(http.StatusOK, "index.tmpl", &IndexData{
|
2024-02-12 13:20:38 +00:00
|
|
|
Base: &components.Base{
|
2024-02-15 22:47:56 +00:00
|
|
|
NavbarActive: GetPageByTitle(Pages, "Status"),
|
|
|
|
Navbar: Pages,
|
2024-02-12 13:20:38 +00:00
|
|
|
},
|
|
|
|
HealthChecks: []*HealthCheck{
|
|
|
|
newMockHealthCheck("example.com"),
|
|
|
|
newMockHealthCheck("example.org"),
|
|
|
|
newMockHealthCheck("example.net"),
|
|
|
|
newMockHealthCheck("foo.example.net"),
|
|
|
|
},
|
2024-02-12 10:22:14 +00:00
|
|
|
})
|
2024-02-10 11:59:58 +00:00
|
|
|
}
|