50 lines
1.1 KiB
Go
50 lines
1.1 KiB
Go
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)
|
|
})
|
|
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)
|
|
}
|
|
}
|