67 lines
1.4 KiB
Go
67 lines
1.4 KiB
Go
// internal/config/config.go
|
|
package config
|
|
|
|
import (
|
|
"os"
|
|
)
|
|
|
|
// Config holds all configuration for the application
|
|
type Config struct {
|
|
Database DatabaseConfig
|
|
JWT JWTConfig
|
|
Server ServerConfig
|
|
}
|
|
|
|
// ServerConfig holds server configuration
|
|
type ServerConfig struct {
|
|
Port string
|
|
Environment string
|
|
UploadPath string
|
|
MaxUploadSize int64
|
|
AllowedOrigins []string
|
|
}
|
|
|
|
// GetConfig returns the application configuration
|
|
func GetConfig() *Config {
|
|
return &Config{
|
|
Database: GetDatabaseConfig(),
|
|
JWT: GetJWTConfig(),
|
|
Server: GetServerConfig(),
|
|
}
|
|
}
|
|
|
|
// GetServerConfig returns server configuration from environment
|
|
func GetServerConfig() ServerConfig {
|
|
port := os.Getenv("PORT")
|
|
if port == "" {
|
|
port = "8080"
|
|
}
|
|
|
|
env := os.Getenv("ENVIRONMENT")
|
|
if env == "" {
|
|
env = "development"
|
|
}
|
|
|
|
uploadPath := os.Getenv("UPLOAD_PATH")
|
|
if uploadPath == "" {
|
|
uploadPath = "./uploads"
|
|
}
|
|
|
|
return ServerConfig{
|
|
Port: port,
|
|
Environment: env,
|
|
UploadPath: uploadPath,
|
|
MaxUploadSize: 10 * 1024 * 1024, // 10MB
|
|
AllowedOrigins: []string{"*"}, // In production, specify exact origins
|
|
}
|
|
}
|
|
|
|
// IsProduction checks if running in production environment
|
|
func IsProduction() bool {
|
|
return os.Getenv("ENVIRONMENT") == "production"
|
|
}
|
|
|
|
// IsDevelopment checks if running in development environment
|
|
func IsDevelopment() bool {
|
|
return os.Getenv("ENVIRONMENT") != "production"
|
|
} |