- Add initial project scaffolding with Go module and project structure - Create server and CLI entry points for application - Implement Makefile with development and build commands - Add `.env.example` with comprehensive configuration template - Set up README.md with project documentation and setup instructions - Configure basic dependencies for server, database, and CLI tools - Establish internal package structure for models, services, and handlers - Add initial configuration and environment management - Prepare for HTTP server, CLI, and database integration
123 lines
2.5 KiB
Go
123 lines
2.5 KiB
Go
package config
|
|
|
|
import (
|
|
"os"
|
|
"strconv"
|
|
"time"
|
|
)
|
|
|
|
type Config struct {
|
|
Server ServerConfig
|
|
Database DatabaseConfig
|
|
JWT JWTConfig
|
|
Stripe StripeConfig
|
|
SMTP SMTPConfig
|
|
Jitsi JitsiConfig
|
|
}
|
|
|
|
type ServerConfig struct {
|
|
Port string
|
|
Host string
|
|
}
|
|
|
|
type DatabaseConfig struct {
|
|
Host string
|
|
Port string
|
|
User string
|
|
Password string
|
|
Name string
|
|
SSLMode string
|
|
}
|
|
|
|
type JWTConfig struct {
|
|
Secret string
|
|
Expiration time.Duration
|
|
}
|
|
|
|
type StripeConfig struct {
|
|
SecretKey string
|
|
WebhookSecret string
|
|
PublishableKey string
|
|
}
|
|
|
|
type SMTPConfig struct {
|
|
Host string
|
|
Port int
|
|
Username string
|
|
Password string
|
|
From string
|
|
}
|
|
|
|
type JitsiConfig struct {
|
|
BaseURL string
|
|
APIKey string
|
|
AppID string
|
|
PrivateKey string
|
|
}
|
|
|
|
func Load() (*Config, error) {
|
|
cfg := &Config{
|
|
Server: ServerConfig{
|
|
Port: getEnv("PORT", "8080"),
|
|
Host: getEnv("HOST", "localhost"),
|
|
},
|
|
Database: DatabaseConfig{
|
|
Host: getEnv("DB_HOST", "localhost"),
|
|
Port: getEnv("DB_PORT", "5432"),
|
|
User: getEnv("DB_USER", "postgres"),
|
|
Password: getEnv("DB_PASSWORD", ""),
|
|
Name: getEnv("DB_NAME", "booking_system"),
|
|
SSLMode: getEnv("DB_SSLMODE", "disable"),
|
|
},
|
|
JWT: JWTConfig{
|
|
Secret: getEnv("JWT_SECRET", "your-secret-key"),
|
|
Expiration: getEnvDuration("JWT_EXPIRATION", 24*time.Hour),
|
|
},
|
|
Stripe: StripeConfig{
|
|
SecretKey: getEnv("STRIPE_SECRET_KEY", ""),
|
|
WebhookSecret: getEnv("STRIPE_WEBHOOK_SECRET", ""),
|
|
PublishableKey: getEnv("STRIPE_PUBLISHABLE_KEY", ""),
|
|
},
|
|
SMTP: SMTPConfig{
|
|
Host: getEnv("SMTP_HOST", ""),
|
|
Port: getEnvInt("SMTP_PORT", 587),
|
|
Username: getEnv("SMTP_USERNAME", ""),
|
|
Password: getEnv("SMTP_PASSWORD", ""),
|
|
From: getEnv("SMTP_FROM", ""),
|
|
},
|
|
Jitsi: JitsiConfig{
|
|
BaseURL: getEnv("JITSI_BASE_URL", ""),
|
|
APIKey: getEnv("JITSI_API_KEY", ""),
|
|
AppID: getEnv("JITSI_APP_ID", ""),
|
|
PrivateKey: getEnv("JITSI_PRIVATE_KEY", ""),
|
|
},
|
|
}
|
|
|
|
return cfg, nil
|
|
}
|
|
|
|
func getEnv(key, defaultValue string) string {
|
|
if value := os.Getenv(key); value != "" {
|
|
return value
|
|
}
|
|
return defaultValue
|
|
}
|
|
|
|
func getEnvInt(key string, defaultValue int) int {
|
|
if value := os.Getenv(key); value != "" {
|
|
if intValue, err := strconv.Atoi(value); err == nil {
|
|
return intValue
|
|
}
|
|
}
|
|
return defaultValue
|
|
}
|
|
|
|
func getEnvDuration(key string, defaultValue time.Duration) time.Duration {
|
|
if value := os.Getenv(key); value != "" {
|
|
if duration, err := time.ParseDuration(value); err == nil {
|
|
return duration
|
|
}
|
|
}
|
|
return defaultValue
|
|
}
|