mirror of
https://github.com/Dvorinka/Trackeep.git
synced 2026-06-03 20:12:58 +00:00
small fix, don't worry about it
This commit is contained in:
@@ -41,7 +41,7 @@ type AppConfig struct {
|
||||
func Load() *Config {
|
||||
return &Config{
|
||||
Server: ServerConfig{
|
||||
Port: getEnvWithDefault("BACKEND_PORT", getEnvWithDefault("PORT", "8080")),
|
||||
Port: getEnvWithDefault("PORT", getEnvWithDefault("BACKEND_PORT", "8080")),
|
||||
ReadTimeout: getDurationEnv("READ_TIMEOUT", 15*time.Second),
|
||||
WriteTimeout: getDurationEnv("WRITE_TIMEOUT", 15*time.Second),
|
||||
IdleTimeout: getDurationEnv("IDLE_TIMEOUT", 60*time.Second),
|
||||
|
||||
@@ -3,6 +3,7 @@ package config
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/trackeep/backend/migrations"
|
||||
"go.uber.org/zap"
|
||||
@@ -24,6 +25,10 @@ func getJWTSecret() string {
|
||||
return "your-secret-key-change-in-production"
|
||||
}
|
||||
|
||||
func shouldRunLegacySQLMigrations() bool {
|
||||
return strings.EqualFold(strings.TrimSpace(os.Getenv("RUN_LEGACY_SQL_MIGRATIONS")), "true")
|
||||
}
|
||||
|
||||
// InitDatabase initializes the database connection
|
||||
func InitDatabase() {
|
||||
// Initialize logger first
|
||||
@@ -39,7 +44,9 @@ func InitDatabase() {
|
||||
var err error
|
||||
|
||||
// Configure GORM
|
||||
gormConfig := &gorm.Config{}
|
||||
gormConfig := &gorm.Config{
|
||||
DisableForeignKeyConstraintWhenMigrating: true,
|
||||
}
|
||||
|
||||
dbType := os.Getenv("DB_TYPE")
|
||||
if dbType == "" {
|
||||
@@ -68,9 +75,15 @@ func InitDatabase() {
|
||||
|
||||
logger.Info("Database connected successfully")
|
||||
|
||||
// Run database migrations
|
||||
if err := migrations.RunMigrations(); err != nil {
|
||||
logger.Fatal("Failed to run database migrations", zap.Error(err))
|
||||
// The checked-in Goose bootstrap targets an older UUID-based schema.
|
||||
// Use it only when explicitly requested; the current application schema is
|
||||
// maintained via GORM auto-migrations during startup.
|
||||
if shouldRunLegacySQLMigrations() {
|
||||
if err := migrations.RunMigrations(); err != nil {
|
||||
logger.Fatal("Failed to run legacy database migrations", zap.Error(err))
|
||||
}
|
||||
} else {
|
||||
logger.Info("Skipping legacy SQL migrations; relying on GORM auto-migration for the current schema")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// ProductionConfig holds production-specific configuration
|
||||
type ProductionConfig struct {
|
||||
// Database connection pooling
|
||||
MaxOpenConns int
|
||||
MaxIdleConns int
|
||||
ConnMaxLifetime time.Duration
|
||||
ConnMaxIdleTime time.Duration
|
||||
|
||||
// Rate limiting
|
||||
EnableRateLimiting bool
|
||||
RateLimitPerMinute int
|
||||
|
||||
// Logging
|
||||
LogLevel string
|
||||
EnableMetrics bool
|
||||
|
||||
// Security
|
||||
EnableCSRF bool
|
||||
SecureCookies bool
|
||||
HTTPSOnly bool
|
||||
HSTSMaxAge int
|
||||
ContentSecPolicy string
|
||||
|
||||
// Performance
|
||||
EnableGzip bool
|
||||
EnableCaching bool
|
||||
CacheTTL time.Duration
|
||||
EnableCompression bool
|
||||
|
||||
// Monitoring
|
||||
EnableHealthChecks bool
|
||||
HealthCheckPath string
|
||||
MetricsPath string
|
||||
}
|
||||
|
||||
// DefaultProductionConfig returns default production configuration
|
||||
func DefaultProductionConfig() ProductionConfig {
|
||||
return ProductionConfig{
|
||||
// Database
|
||||
MaxOpenConns: 25,
|
||||
MaxIdleConns: 10,
|
||||
ConnMaxLifetime: time.Hour,
|
||||
ConnMaxIdleTime: 10 * time.Minute,
|
||||
|
||||
// Rate limiting
|
||||
EnableRateLimiting: true,
|
||||
RateLimitPerMinute: 60,
|
||||
|
||||
// Logging
|
||||
LogLevel: "info",
|
||||
EnableMetrics: true,
|
||||
|
||||
// Security
|
||||
EnableCSRF: true,
|
||||
SecureCookies: true,
|
||||
HTTPSOnly: true,
|
||||
HSTSMaxAge: 31536000, // 1 year
|
||||
ContentSecPolicy: "default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; style-src 'self' 'unsafe-inline';",
|
||||
|
||||
// Performance
|
||||
EnableGzip: true,
|
||||
EnableCaching: true,
|
||||
CacheTTL: 5 * time.Minute,
|
||||
EnableCompression: true,
|
||||
|
||||
// Monitoring
|
||||
EnableHealthChecks: true,
|
||||
HealthCheckPath: "/health",
|
||||
MetricsPath: "/metrics",
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
package config
|
||||
|
||||
const ControlServiceURL = "https://hq.trackeep.org"
|
||||
Reference in New Issue
Block a user