config.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. S3PublicEndpoint string
  14. S3AccessKey string
  15. S3SecretKey string
  16. S3Bucket string
  17. JWTSecret string
  18. JWTRefreshSecret string
  19. CloudPaymentsPublicID string
  20. CloudPaymentsAPISecret string
  21. AllowedOrigins []string
  22. }
  23. func Load() *Config {
  24. godotenv.Load()
  25. cfg := &Config{
  26. AppEnv: getEnv("APP_ENV", "development"),
  27. ServerPort: getEnv("SERVER_PORT", "8080"),
  28. DatabaseURL: getEnv("DATABASE_URL", "postgres://photoplaces:photoplaces_dev@localhost:5432/photoplaces?sslmode=disable"),
  29. RedisURL: getEnv("REDIS_URL", "redis://localhost:6379/0"),
  30. S3Endpoint: getEnv("S3_ENDPOINT", "http://localhost:9000"),
  31. S3PublicEndpoint: getEnv("S3_PUBLIC_ENDPOINT", "http://localhost:9000"),
  32. S3AccessKey: getEnv("S3_ACCESS_KEY", "photoplaces"),
  33. S3SecretKey: getEnv("S3_SECRET_KEY", "photoplaces_dev"),
  34. S3Bucket: getEnv("S3_BUCKET", "photoplaces"),
  35. JWTSecret: getEnv("JWT_SECRET", "dev-secret"),
  36. JWTRefreshSecret: getEnv("JWT_REFRESH_SECRET", "dev-refresh-secret"),
  37. CloudPaymentsPublicID: getEnv("CLOUDPAYMENTS_PUBLIC_ID", ""),
  38. CloudPaymentsAPISecret: getEnv("CLOUDPAYMENTS_API_SECRET", ""),
  39. AllowedOrigins: strings.Split(getEnv("ALLOWED_ORIGINS", "http://localhost:3000"), ","),
  40. }
  41. return cfg
  42. }
  43. func getEnv(key, fallback string) string {
  44. if v := os.Getenv(key); v != "" {
  45. return v
  46. }
  47. return fallback
  48. }