config.go 908 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. package config
  2. import (
  3. "os"
  4. )
  5. // Config holds the application configuration
  6. type Config struct {
  7. DBHost string
  8. DBPort string
  9. DBUser string
  10. DBPassword string
  11. DBName string
  12. JWTSecret string
  13. ServerPort string
  14. GinMode string
  15. }
  16. // Load reads configuration from environment variables with fallbacks
  17. func Load() *Config {
  18. return &Config{
  19. DBHost: getEnv("DB_HOST", "localhost"),
  20. DBPort: getEnv("DB_PORT", "5432"),
  21. DBUser: getEnv("DB_USER", "celestia"),
  22. DBPassword: getEnv("DB_PASSWORD", "celestia_secret"),
  23. DBName: getEnv("DB_NAME", "celestia_trace"),
  24. JWTSecret: getEnv("JWT_SECRET", "change-me-in-production"),
  25. ServerPort: getEnv("SERVER_PORT", "8080"),
  26. GinMode: getEnv("GIN_MODE", "release"),
  27. }
  28. }
  29. func getEnv(key, fallback string) string {
  30. if value, exists := os.LookupEnv(key); exists {
  31. return value
  32. }
  33. return fallback
  34. }