2024-11-28 13:52:58 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
|
|
|
|
"heating-monitor/internal/config"
|
|
|
|
"heating-monitor/internal/web"
|
|
|
|
|
|
|
|
"github.com/labstack/echo/v4"
|
|
|
|
"github.com/labstack/echo/v4/middleware"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
// Cargar configuración
|
|
|
|
cfg, err := config.LoadConfig()
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("Error al cargar la configuración: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Inicializar la base de datos
|
|
|
|
config.InitDB()
|
|
|
|
|
|
|
|
// Crear instancia de Echo
|
|
|
|
e := echo.New()
|
|
|
|
|
|
|
|
// Middleware de logging
|
|
|
|
e.Use(middleware.Logger())
|
|
|
|
e.Use(middleware.Recover())
|
|
|
|
|
|
|
|
// Rutas
|
|
|
|
e.GET("/", func(c echo.Context) error {
|
|
|
|
return web.GetEventsHandler(c, config.DB)
|
|
|
|
})
|
|
|
|
e.GET("/events/edit/:id", func(c echo.Context) error {
|
|
|
|
return web.GetEventHandler(c, config.DB)
|
|
|
|
})
|
|
|
|
e.POST("/events/edit/:id", func(c echo.Context) error {
|
|
|
|
return web.UpdateEventHandler(c, config.DB)
|
|
|
|
})
|
2024-11-28 22:51:32 +01:00
|
|
|
e.POST("/events/del/:id", func(c echo.Context) error {
|
|
|
|
return web.DeleteEventHandler(c, config.DB)
|
|
|
|
})
|
2024-11-28 13:52:58 +01:00
|
|
|
e.GET("/about", func(c echo.Context) error {
|
|
|
|
return web.AboutHandler(c, config.DB)
|
|
|
|
})
|
|
|
|
|
|
|
|
// Iniciar servidor
|
|
|
|
log.Printf("Servidor web escuchando en http://localhost:%s", cfg.WebPort)
|
|
|
|
if err := e.Start(":" + cfg.WebPort); err != nil {
|
|
|
|
log.Fatalf("Error al iniciar el servidor web: %v", err)
|
|
|
|
}
|
|
|
|
}
|