---
title: Do Not Hardcode Configuration
impact: HIGH
impactDescription: enables environment-specific deployments
tags: configuration, environment, deployment, quality
---

## Do Not Hardcode Configuration

Hardcoded configuration requires code changes to deploy to different environments.

**Incorrect (hardcoded config):**

```go
const APIUrl = "https://api.production.example.com"
const Timeout = 5000
const MaxFileSize = 10485760
```

**Correct (externalized config):**

```go
type Config struct {
    API struct {
        URL     string
        Timeout time.Duration
    }
    Upload struct {
        MaxFileSize int64
    }
}

func LoadConfig() *Config {
    return &Config{
        API: struct {
            URL     string
            Timeout time.Duration
        }{
            URL:     getEnv("API_URL", "http://localhost:3000"),
            Timeout: time.Duration(getEnvInt("API_TIMEOUT", 5000)) * time.Millisecond,
        },
        // ...
    }
}

// Usage
cfg := LoadConfig()
client := &http.Client{Timeout: cfg.API.Timeout}
```

**Tools:** `os.Getenv`, `viper`, `clever-env`, Manual review
