| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- package config
- import (
- "os"
- "strings"
- "github.com/joho/godotenv"
- )
- type Config struct {
- AppEnv string
- ServerPort string
- DatabaseURL string
- RedisURL string
- S3Endpoint string
- S3PublicEndpoint string
- S3AccessKey string
- S3SecretKey string
- S3Bucket string
- JWTSecret string
- JWTRefreshSecret string
- CloudPaymentsPublicID string
- CloudPaymentsAPISecret string
- AllowedOrigins []string
- }
- func Load() *Config {
- godotenv.Load()
- cfg := &Config{
- AppEnv: getEnv("APP_ENV", "development"),
- ServerPort: getEnv("SERVER_PORT", "8080"),
- DatabaseURL: getEnv("DATABASE_URL", "postgres://photoplaces:photoplaces_dev@localhost:5432/photoplaces?sslmode=disable"),
- RedisURL: getEnv("REDIS_URL", "redis://localhost:6379/0"),
- S3Endpoint: getEnv("S3_ENDPOINT", "http://localhost:9000"),
- S3PublicEndpoint: getEnv("S3_PUBLIC_ENDPOINT", "http://localhost:9000"),
- S3AccessKey: getEnv("S3_ACCESS_KEY", "photoplaces"),
- S3SecretKey: getEnv("S3_SECRET_KEY", "photoplaces_dev"),
- S3Bucket: getEnv("S3_BUCKET", "photoplaces"),
- JWTSecret: getEnv("JWT_SECRET", "dev-secret"),
- JWTRefreshSecret: getEnv("JWT_REFRESH_SECRET", "dev-refresh-secret"),
- CloudPaymentsPublicID: getEnv("CLOUDPAYMENTS_PUBLIC_ID", ""),
- CloudPaymentsAPISecret: getEnv("CLOUDPAYMENTS_API_SECRET", ""),
- AllowedOrigins: strings.Split(getEnv("ALLOWED_ORIGINS", "http://localhost:3000"), ","),
- }
- return cfg
- }
- func getEnv(key, fallback string) string {
- if v := os.Getenv(key); v != "" {
- return v
- }
- return fallback
- }
|