feat: PKI API Go avec persistance MongoDB et abstraction storage
- API REST complète pour gestion Infrastructure à Clé Publique - Authentification JWT sur tous les endpoints (sauf login) - Hiérarchie de certificats (Root CA, Sub-CA, End Certificates) - Abstraction de stockage avec MemoryStore et MongoStore - Configuration centralisée via variables d'environnement - Support déploiement Docker Compose avec MongoDB - Tests unitaires pour sérialisation des clés RSA - Documentation complète avec exemples API
This commit is contained in:
38
internal/config/config.go
Normal file
38
internal/config/config.go
Normal file
@@ -0,0 +1,38 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user