Inicial
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"os"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
DatabaseURL string
|
||||
RedisURL string
|
||||
JWTSecret string
|
||||
Port string
|
||||
AppEnv string
|
||||
InitialAdminEmail string
|
||||
InitialAdminPassword string
|
||||
}
|
||||
|
||||
func Load() (*Config, error) {
|
||||
dbURL := os.Getenv("DATABASE_URL")
|
||||
if dbURL == "" {
|
||||
return nil, errors.New("DATABASE_URL is required")
|
||||
}
|
||||
|
||||
jwtSecret := os.Getenv("JWT_SECRET")
|
||||
if jwtSecret == "" {
|
||||
return nil, errors.New("JWT_SECRET is required")
|
||||
}
|
||||
|
||||
redisURL := os.Getenv("REDIS_URL")
|
||||
if redisURL == "" {
|
||||
redisURL = "redis://localhost:6379"
|
||||
}
|
||||
|
||||
port := os.Getenv("PORT")
|
||||
if port == "" {
|
||||
port = "8080"
|
||||
}
|
||||
|
||||
appEnv := os.Getenv("APP_ENV")
|
||||
if appEnv == "" {
|
||||
appEnv = "development"
|
||||
}
|
||||
|
||||
return &Config{
|
||||
DatabaseURL: dbURL,
|
||||
RedisURL: redisURL,
|
||||
JWTSecret: jwtSecret,
|
||||
Port: port,
|
||||
AppEnv: appEnv,
|
||||
InitialAdminEmail: os.Getenv("INITIAL_ADMIN_EMAIL"),
|
||||
InitialAdminPassword: os.Getenv("INITIAL_ADMIN_PASSWORD"),
|
||||
}, nil
|
||||
}
|
||||
Reference in New Issue
Block a user