fix: layout CSS en Cloudflare/Hostinger + sesiones en PostgreSQL 1 año
This commit is contained in:
+1
-1
@@ -91,7 +91,7 @@ func (cfg *AppConfig) LoadComponents() {
|
|||||||
cfg.LoadStatic()
|
cfg.LoadStatic()
|
||||||
cfg.PrepareLog()
|
cfg.PrepareLog()
|
||||||
_ = cfg.Database.Setup()
|
_ = cfg.Database.Setup()
|
||||||
_ = cfg.Session.Setup()
|
_ = cfg.Session.Setup(cfg.Database.Default)
|
||||||
cfg.Cache.Setup()
|
cfg.Cache.Setup()
|
||||||
cfg.Storage.Setup()
|
cfg.Storage.Setup()
|
||||||
}
|
}
|
||||||
|
|||||||
+18
-30
@@ -1,49 +1,37 @@
|
|||||||
package config
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gofiber/session/v2"
|
"github.com/gofiber/session/v2"
|
||||||
"gorm.io/driver/sqlite"
|
pgprovider "github.com/gofiber/session/v2/provider/postgres"
|
||||||
"gorm.io/gorm"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type SessionConfig struct {
|
type SessionConfig struct {
|
||||||
Database string `yaml:"database" env:"SESSION_DATABASE"` // Ruta de la base de datos SQLite
|
|
||||||
*session.Session
|
*session.Session
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SessionConfig) Setup() error {
|
// Setup configura el almacén de sesiones en PostgreSQL con expiración de 1 año.
|
||||||
// Abrir conexión a la base de datos SQLite
|
func (s *SessionConfig) Setup(db DatabaseDriver) error {
|
||||||
db, err := gorm.Open(sqlite.Open(s.Database), &gorm.Config{})
|
provider, err := pgprovider.New(pgprovider.Config{
|
||||||
|
Host: db.Host,
|
||||||
|
Port: int64(db.Port),
|
||||||
|
Username: db.Username,
|
||||||
|
Password: db.Password,
|
||||||
|
Database: db.DBName,
|
||||||
|
TableName: "sessions",
|
||||||
|
MaxOpenConns: 20,
|
||||||
|
MaxIdleConns: 10,
|
||||||
|
ConnMaxLifetime: 5 * time.Minute,
|
||||||
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to connect to the database: %v", err)
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Migrar la estructura de la tabla para sesiones
|
s.Session = session.New(session.Config{
|
||||||
err = db.AutoMigrate(&Session{}) // Define la estructura de la sesión según sea necesario
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("failed to migrate database: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Configurar el proveedor de sesiones en memoria
|
|
||||||
store := session.New(session.Config{
|
|
||||||
Expiration: 365 * 24 * time.Hour, // 1 año
|
Expiration: 365 * 24 * time.Hour, // 1 año
|
||||||
}) // Usar el proveedor de sesiones en memoria
|
Provider: provider,
|
||||||
|
})
|
||||||
// Crear una nueva sesión
|
|
||||||
s.Session = store
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Estructura para las sesiones (ajusta según tus necesidades)
|
|
||||||
type Session struct {
|
|
||||||
ID uint `gorm:"primaryKey"`
|
|
||||||
SessionID string `gorm:"unique"`
|
|
||||||
Data string `gorm:"type:text"`
|
|
||||||
CreatedAt time.Time
|
|
||||||
UpdatedAt time.Time
|
|
||||||
ExpireAt time.Time
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -45,8 +45,12 @@ require (
|
|||||||
require (
|
require (
|
||||||
github.com/aliyun/aliyun-oss-go-sdk v3.0.2+incompatible
|
github.com/aliyun/aliyun-oss-go-sdk v3.0.2+incompatible
|
||||||
github.com/chai2010/webp v1.4.0
|
github.com/chai2010/webp v1.4.0
|
||||||
|
github.com/go-sql-driver/mysql v1.8.1
|
||||||
|
github.com/jackc/pgx/v5 v5.7.1
|
||||||
github.com/mattn/go-sqlite3 v1.14.22
|
github.com/mattn/go-sqlite3 v1.14.22
|
||||||
|
github.com/microsoft/go-mssqldb v1.7.2
|
||||||
github.com/oarkflow/log v1.0.79
|
github.com/oarkflow/log v1.0.79
|
||||||
|
github.com/robfig/cron/v3 v3.0.1
|
||||||
github.com/sirupsen/logrus v1.9.3
|
github.com/sirupsen/logrus v1.9.3
|
||||||
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e
|
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e
|
||||||
gorm.io/driver/sqlite v1.5.6
|
gorm.io/driver/sqlite v1.5.6
|
||||||
@@ -72,7 +76,6 @@ require (
|
|||||||
github.com/go-openapi/jsonpointer v0.21.0 // indirect
|
github.com/go-openapi/jsonpointer v0.21.0 // indirect
|
||||||
github.com/go-openapi/jsonreference v0.21.0 // indirect
|
github.com/go-openapi/jsonreference v0.21.0 // indirect
|
||||||
github.com/go-openapi/swag v0.23.0 // indirect
|
github.com/go-openapi/swag v0.23.0 // indirect
|
||||||
github.com/go-sql-driver/mysql v1.8.1 // indirect
|
|
||||||
github.com/go-test/deep v1.1.0 // indirect
|
github.com/go-test/deep v1.1.0 // indirect
|
||||||
github.com/gogo/protobuf v1.3.2 // indirect
|
github.com/gogo/protobuf v1.3.2 // indirect
|
||||||
github.com/golang-jwt/jwt/v5 v5.2.1 // indirect
|
github.com/golang-jwt/jwt/v5 v5.2.1 // indirect
|
||||||
@@ -89,7 +92,6 @@ require (
|
|||||||
github.com/hashicorp/golang-lru v1.0.2 // indirect
|
github.com/hashicorp/golang-lru v1.0.2 // indirect
|
||||||
github.com/jackc/pgpassfile v1.0.0 // indirect
|
github.com/jackc/pgpassfile v1.0.0 // indirect
|
||||||
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
|
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
|
||||||
github.com/jackc/pgx/v5 v5.7.1 // indirect
|
|
||||||
github.com/jackc/puddle/v2 v2.2.2 // indirect
|
github.com/jackc/puddle/v2 v2.2.2 // indirect
|
||||||
github.com/jinzhu/inflection v1.0.0 // indirect
|
github.com/jinzhu/inflection v1.0.0 // indirect
|
||||||
github.com/jinzhu/now v1.1.5 // indirect
|
github.com/jinzhu/now v1.1.5 // indirect
|
||||||
@@ -98,9 +100,9 @@ require (
|
|||||||
github.com/klauspost/compress v1.17.10 // indirect
|
github.com/klauspost/compress v1.17.10 // indirect
|
||||||
github.com/kr/pretty v0.3.1 // indirect
|
github.com/kr/pretty v0.3.1 // indirect
|
||||||
github.com/kr/text v0.2.0 // indirect
|
github.com/kr/text v0.2.0 // indirect
|
||||||
|
github.com/lib/pq v1.10.9 // indirect
|
||||||
github.com/mailru/easyjson v0.7.7 // indirect
|
github.com/mailru/easyjson v0.7.7 // indirect
|
||||||
github.com/mattn/go-runewidth v0.0.16 // indirect
|
github.com/mattn/go-runewidth v0.0.16 // indirect
|
||||||
github.com/microsoft/go-mssqldb v1.7.2 // indirect
|
|
||||||
github.com/mitchellh/go-ps v1.0.0 // indirect
|
github.com/mitchellh/go-ps v1.0.0 // indirect
|
||||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||||
@@ -111,7 +113,6 @@ require (
|
|||||||
github.com/pyroscope-io/dotnetdiag v1.2.1 // indirect
|
github.com/pyroscope-io/dotnetdiag v1.2.1 // indirect
|
||||||
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
|
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
|
||||||
github.com/rivo/uniseg v0.4.7 // indirect
|
github.com/rivo/uniseg v0.4.7 // indirect
|
||||||
github.com/robfig/cron/v3 v3.0.1 // indirect
|
|
||||||
github.com/rogpeppe/go-internal v1.12.0 // indirect
|
github.com/rogpeppe/go-internal v1.12.0 // indirect
|
||||||
github.com/savsgio/gotils v0.0.0-20240704082632-aef3928b8a38 // indirect
|
github.com/savsgio/gotils v0.0.0-20240704082632-aef3928b8a38 // indirect
|
||||||
github.com/stretchr/testify v1.10.0 // indirect
|
github.com/stretchr/testify v1.10.0 // indirect
|
||||||
|
|||||||
@@ -11,10 +11,13 @@ import (
|
|||||||
// CloudflareConfigPage renderiza la vista de gestión de Cloudflare.
|
// CloudflareConfigPage renderiza la vista de gestión de Cloudflare.
|
||||||
func CloudflareConfigPage(c *fiber.Ctx) error {
|
func CloudflareConfigPage(c *fiber.Ctx) error {
|
||||||
cfg, _ := models.GetCloudflareConfig()
|
cfg, _ := models.GetCloudflareConfig()
|
||||||
return c.Render("cloudflare", fiber.Map{
|
if err := c.Render("cloudflare", fiber.Map{
|
||||||
"Title": "Cloudflare API",
|
"Title": "Cloudflare API",
|
||||||
"Config": cfg,
|
"Config": cfg,
|
||||||
})
|
}, "layouts/main"); err != nil {
|
||||||
|
return c.SendStatus(fiber.StatusInternalServerError)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// SaveCloudflareConfig guarda o actualiza el API token de Cloudflare.
|
// SaveCloudflareConfig guarda o actualiza el API token de Cloudflare.
|
||||||
|
|||||||
@@ -11,10 +11,13 @@ import (
|
|||||||
// HostingerConfigPage renderiza la vista de gestión de Hostinger.
|
// HostingerConfigPage renderiza la vista de gestión de Hostinger.
|
||||||
func HostingerConfigPage(c *fiber.Ctx) error {
|
func HostingerConfigPage(c *fiber.Ctx) error {
|
||||||
cfg, _ := models.GetHostingerConfig()
|
cfg, _ := models.GetHostingerConfig()
|
||||||
return c.Render("hostinger", fiber.Map{
|
if err := c.Render("hostinger", fiber.Map{
|
||||||
"Title": "Hostinger API",
|
"Title": "Hostinger API",
|
||||||
"Config": cfg,
|
"Config": cfg,
|
||||||
})
|
}, "layouts/main"); err != nil {
|
||||||
|
return c.SendStatus(fiber.StatusInternalServerError)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// SaveHostingerConfig guarda o actualiza el token de Hostinger.
|
// SaveHostingerConfig guarda o actualiza el token de Hostinger.
|
||||||
|
|||||||
Reference in New Issue
Block a user