39 lines
911 B
Go
39 lines
911 B
Go
package config
|
|
|
|
import (
|
|
"os"
|
|
)
|
|
|
|
// Config contient les paramètres de configuration de l'API
|
|
type Config struct {
|
|
// HTTP
|
|
Port string
|
|
|
|
// JWT
|
|
JWTSecretKey string
|
|
|
|
// Storage
|
|
StorageType string // "memory" ou "mongodb"
|
|
MongoURI string
|
|
MongoDB string
|
|
}
|
|
|
|
// LoadConfig charge la configuration depuis les variables d'environnement
|
|
func LoadConfig() *Config {
|
|
return &Config{
|
|
Port: getEnv("PORT", "8080"),
|
|
JWTSecretKey: getEnv("JWT_SECRET_KEY", "your-secret-key-change-in-prod"),
|
|
StorageType: getEnv("STORAGE_TYPE", "memory"), // "memory" ou "mongodb"
|
|
MongoURI: getEnv("MONGO_URI", "mongodb://localhost:27017"),
|
|
MongoDB: getEnv("MONGO_DB", "pkiapi"),
|
|
}
|
|
}
|
|
|
|
// getEnv obtient une variable d'environnement ou retourne une valeur par défaut
|
|
func getEnv(key, defaultValue string) string {
|
|
if value := os.Getenv(key); value != "" {
|
|
return value
|
|
}
|
|
return defaultValue
|
|
}
|