package config import ( "strings" "git.secnex.io/secnex/auth-api/utils" ) type Config struct { Debug bool FiberShowStartupMessage bool CorsAllowOrigins string CorsAllowHeaders string CorsAllowMethods string Address string DatabaseHost string DatabasePort string DatabaseUser string DatabasePassword string DatabaseName string RedisHost string RedisPort string RedisPassword string JwtSecret string Environment string UnprotectedEndpoints []string AllowRegistration bool AllowTenantCreation bool } var CONFIG *Config func generateSecret() string { return utils.GenerateRandomString(32) } func NewConfig() *Config { Environment := utils.GetEnv("ENV", "development") UnprotectedEndpoints := strings.Split(utils.GetEnv("UNPROTECTED_ENDPOINTS", ""), ",") if Environment == "development" { UnprotectedEndpoints = append(UnprotectedEndpoints, "/api_keys") } c := &Config{ Debug: utils.GetEnvBool("DEBUG", false), FiberShowStartupMessage: utils.GetEnvBool("FIBER_SHOW_STARTUP_MESSAGE", false), CorsAllowOrigins: utils.GetEnv("CORS_ALLOW_ORIGINS", "*"), CorsAllowHeaders: utils.GetEnv("CORS_ALLOW_HEADERS", "Origin, Content-Type, Accept"), CorsAllowMethods: utils.GetEnv("CORS_ALLOW_METHODS", "GET, POST, PUT, DELETE"), Address: utils.GetEnv("ADDRESS", ":3000"), DatabaseHost: utils.GetEnv("DATABASE_HOST", "localhost"), DatabasePort: utils.GetEnv("DATABASE_PORT", "5432"), DatabaseUser: utils.GetEnv("DATABASE_USER", "postgres"), DatabasePassword: utils.GetEnv("DATABASE_PASSWORD", "postgres"), DatabaseName: utils.GetEnv("DATABASE_NAME", "secnex"), JwtSecret: utils.GetEnv("JWT_SECRET", "your-256-bit-secret"), RedisHost: utils.GetEnv("REDIS_HOST", "localhost"), RedisPort: utils.GetEnv("REDIS_PORT", "6379"), RedisPassword: utils.GetEnv("REDIS_PASSWORD", ""), AllowRegistration: utils.GetEnvBool("ALLOW_REGISTRATION", false), AllowTenantCreation: utils.GetEnvBool("ALLOW_TENANT_CREATION", false), Environment: Environment, UnprotectedEndpoints: UnprotectedEndpoints, } CONFIG = c return c }