config.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package config
  2. import (
  3. "os"
  4. "strings"
  5. "github.com/joho/godotenv"
  6. )
  7. type Config struct {
  8. AppEnv string
  9. ServerPort string
  10. DatabaseURL string
  11. RedisURL string
  12. S3Endpoint string
  13. S3AccessKey string
  14. S3SecretKey string
  15. S3Bucket string
  16. JWTSecret string
  17. JWTRefreshSecret string
  18. CloudPaymentsPublicID string
  19. CloudPaymentsAPISecret string
  20. AllowedOrigins []string
  21. }
  22. func Load() *Config {
  23. godotenv.Load()
  24. cfg := &Config{
  25. AppEnv: getEnv("APP_ENV", "development"),
  26. ServerPort: getEnv("SERVER_PORT", "8080"),
  27. DatabaseURL: getEnv("DATABASE_URL", "postgres://photoplaces:photoplaces_dev@localhost:5432/photoplaces?sslmode=disable"),
  28. RedisURL: getEnv("REDIS_URL", "redis://localhost:6379/0"),
  29. S3Endpoint: getEnv("S3_ENDPOINT", "http://localhost:9000"),
  30. S3AccessKey: getEnv("S3_ACCESS_KEY", "photoplaces"),
  31. S3SecretKey: getEnv("S3_SECRET_KEY", "photoplaces_dev"),
  32. S3Bucket: getEnv("S3_BUCKET", "photoplaces"),
  33. JWTSecret: getEnv("JWT_SECRET", "dev-secret"),
  34. JWTRefreshSecret: getEnv("JWT_REFRESH_SECRET", "dev-refresh-secret"),
  35. CloudPaymentsPublicID: getEnv("CLOUDPAYMENTS_PUBLIC_ID", ""),
  36. CloudPaymentsAPISecret: getEnv("CLOUDPAYMENTS_API_SECRET", ""),
  37. AllowedOrigins: strings.Split(getEnv("ALLOWED_ORIGINS", "http://localhost:3000"), ","),
  38. }
  39. return cfg
  40. }
  41. func getEnv(key, fallback string) string {
  42. if v := os.Getenv(key); v != "" {
  43. return v
  44. }
  45. return fallback
  46. }