Configuration

Statigo uses environment variables and JSON configuration files for flexible application configuration.

Environment Variables

Create a .env file in your project root:

# Server Configuration
PORT=8080
BASE_URL=http://localhost:8080

# Logging
LOG_LEVEL=INFO

# Cache
CACHE_DIR=./data/cache
DISABLE_CACHE=false

# Rate Limiting
RATE_LIMIT_RPS=10
RATE_LIMIT_BURST=20

# Development
DEV_MODE=false

# Shutdown Timeout
SHUTDOWN_TIMEOUT=30

# Webhook Secret (for cache invalidation)
WEBHOOK_SECRET=your-webhook-secret-key

# Google Tag Manager (optional)
GTM_ID=GTM-XXXXX

Server Configuration

VariableDefaultDescription
PORT8080HTTP server port
BASE_URLhttp://localhost:8080Base URL for canonical links
DEV_MODEfalseEnable development mode

Logging

VariableDefaultDescription
LOG_LEVELINFOLog level: DEBUG, INFO, WARN, ERROR

Cache

VariableDefaultDescription
CACHE_DIR./data/cacheCache storage directory
DISABLE_CACHEfalseDisable caching (for testing)

Rate Limiting

VariableDefaultDescription
RATE_LIMIT_RPS10Requests per second
RATE_LIMIT_BURST20Burst size

Security

VariableDefaultDescription
WEBHOOK_SECRET-Secret for webhook authentication

Route Configuration

routes.json

Define routes in config/routes.json:

{
  "routes": [
    {
      "canonical": "/",
      "paths": {
        "en": "/en",
        "tr": "/tr"
      },
      "strategy": "static",
      "template": "index.html",
      "handler": "index",
      "title": "pages.home.title"
    }
  ]
}

Route Fields

FieldTypeRequiredDescription
canonicalstringYesInternal canonical path
pathsobjectYesLanguage-specific URL paths
strategystringYesCaching strategy
templatestringYesTemplate file name
handlerstringYesHandler name for customHandlers map
titlestringNoPage title or i18n key

Caching Strategies

  • immutable - Never expires (static assets)
  • static - Long cache, revalidate when stale
  • incremental - Auto-revalidate after 24 hours
  • dynamic - Always revalidate when stale

Redirect Configuration

redirects.json

Define redirects in config/redirects.json:

{
  "redirects": [
    {
      "from": "/old-page",
      "to": "/new-page",
      "type": 301
    },
    {
      "from": "/blog/*",
      "to": "/articles/*",
      "type": 301,
      "pattern": true
    }
  ]
}

Redirect Fields

FieldTypeDescription
fromstringSource path (supports * wildcard)
tostringDestination path (use * for matched part)
typenumberHTTP status code (301 or 302)
patternbooleanEnable wildcard matching

Translation Configuration

Translation files are stored in translations/ directory:

translations/
├── en.json    # English
├── tr.json    # Turkish
└── de.json    # German

Translation File Format

{
  "site": {
    "name": "My Site",
    "description": "A description"
  },
  "nav": {
    "home": "Home",
    "about": "About"
  }
}

Accessing Configuration in Go

Environment Variables

import "statigo/framework/utils"

port := os.Getenv("PORT")
if port == "" {
    port = "8080"
}

// Or use helper
rateLimitRPS := utils.GetEnvInt("RATE_LIMIT_RPS", 10)
rateLimitBurst := utils.GetEnvInt("RATE_LIMIT_BURST", 20)

Loading Routes

import "statigo/framework/router"

routeRegistry := router.NewRegistry([]string{"en", "tr"})

err := router.LoadRoutesFromJSON(
    configFS,
    "routes.json",
    routeRegistry,
    renderer,
    customHandlers,
    logger,
)

Loading Redirects

import "statigo/framework/middleware"

r.Use(middleware.RedirectMiddleware(
    configFS,
    "redirects.json",
    logger,
))

Configuration Best Practices

  1. Never commit .env - Add to .gitignore
  2. Use .env.example - Template for required variables
  3. Validate configuration - Check for required variables on startup
  4. Use sensible defaults - Provide defaults for optional settings
  5. Document variables - Explain what each variable does

Example Configuration

Production (.env.production)

PORT=8080
BASE_URL=https://example.com
LOG_LEVEL=WARN
DEV_MODE=false
RATE_LIMIT_RPS=20
RATE_LIMIT_BURST=40
WEBHOOK_SECRET=prod-secret-key

Development (.env.development)

PORT=3000
BASE_URL=http://localhost:3000
LOG_LEVEL=DEBUG
DEV_MODE=true
RATE_LIMIT_RPS=100
RATE_LIMIT_BURST=200

Testing (.env.test)

PORT=8081
BASE_URL=http://localhost:8081
LOG_LEVEL=ERROR
DEV_MODE=true
DISABLE_CACHE=true
RATE_LIMIT_RPS=1000

Loading Environment Files

Statigo uses godotenv for loading .env files:

import "github.com/joho/godotenv"

func main() {
    // Load .env file
    if err := godotenv.Load(); err != nil {
        log.Println("Warning: No .env file found, using defaults")
    }

    // Your application code...
}

For environment-specific files:

env := os.Getenv("APP_ENV")
if env == "" {
    env = "development"
}

godotenv.Load(".env." + env)
godotenv.Load() // Load default .env as fallback