Storage

Configuration

Config structs, YAML examples, and option helpers for Storage

YAML Configuration Example

config.yaml
extensions:
  storage:
    default: "uploads"
    enablePresignedURLs: true
    presignExpiry: "15m"
    maxUploadSize: 5368709120       # 5 GB
    chunkSize: 5242880              # 5 MB
    enableCDN: false
    cdnBaseURL: ""
    useEnhancedBackend: true

    backends:
      uploads:
        type: "s3"
        config:
          region: "us-east-1"
          bucket: "my-app-uploads"
          prefix: "files/"
          access_key_id: "${AWS_ACCESS_KEY_ID}"
          secret_access_key: "${AWS_SECRET_ACCESS_KEY}"
          endpoint: ""              # custom endpoint for S3-compatible storage
          use_path_style: false

      local:
        type: "local"
        config:
          root_dir: "./storage"
          base_url: "http://localhost:8080/files"

    resilience:
      maxRetries: 3
      initialBackoff: "100ms"
      maxBackoff: "10s"
      backoffMultiplier: 2.0
      circuitBreakerEnabled: true
      circuitBreakerThreshold: 5
      circuitBreakerTimeout: "60s"
      circuitBreakerHalfOpenMax: 3
      rateLimitEnabled: true
      rateLimitPerSec: 100
      rateLimitBurst: 200
      operationTimeout: "30s"

The extension loads config from extensions.storage first, falling back to storage.

Programmatic Configuration

ext := storage.NewExtension(
    storage.WithS3Backend("uploads", "my-bucket", "us-east-1", ""),
    storage.WithLocalBackend("temp", "./tmp", "http://localhost:8080/tmp"),
    storage.WithDefault("uploads"),
    storage.WithPresignedURLs(true, 15*time.Minute),
    storage.WithMaxUploadSize(100 * 1024 * 1024), // 100 MB
)

Config Struct Reference

Config

Source: config.go

FieldTypeDefaultDescription
Defaultstring"local"Name of the default backend
Backendsmap[string]BackendConfigLocal backendNamed backend configurations
EnablePresignedURLsbooltrueEnable presigned URL generation
PresignExpirytime.Duration15mDefault presigned URL expiration
MaxUploadSizeint645368709120 (5 GB)Maximum upload size in bytes
ChunkSizeint5242880 (5 MB)Chunk size for multipart operations
EnableCDNboolfalseRoute URLs through CDN
CDNBaseURLstring""CDN base URL
ResilienceResilienceConfigSee belowResilience wrapper configuration
UseEnhancedBackendbooltrueUse enhanced local backend with locking and pooling
RequireConfigboolfalseFail if config missing from ConfigManager

BackendConfig

FieldTypeDescription
TypeBackendType"local", "s3", "gcs", or "azure"
Configmap[string]anyBackend-specific configuration (see below)

Local Backend Config Keys

KeyDescription
root_dirRoot directory for file storage
base_urlBase URL for generating file URLs
secretHMAC secret for presigned URLs (auto-generated if empty for enhanced backend)
chunk_sizeChunk size for enhanced backend
max_upload_sizeMax upload size for enhanced backend

S3 Backend Config Keys

KeyDescription
regionAWS region
bucketS3 bucket name
prefixKey prefix within the bucket
access_key_idAWS access key ID
secret_access_keyAWS secret access key
session_tokenAWS session token (optional)
endpointCustom endpoint for S3-compatible storage
use_path_styleUse path-style addressing instead of virtual-hosted

ResilienceConfig

FieldTypeDefaultDescription
MaxRetriesint3Max retry attempts
InitialBackofftime.Duration100msInitial retry backoff
MaxBackofftime.Duration10sMaximum retry backoff
BackoffMultiplierfloat642.0Backoff multiplier
CircuitBreakerEnabledbooltrueEnable circuit breaker
CircuitBreakerThresholdint5Failures before opening
CircuitBreakerTimeouttime.Duration60sTime before half-open
CircuitBreakerHalfOpenMaxint3Half-open probe count
RateLimitEnabledbooltrueEnable rate limiting
RateLimitPerSecfloat64100Requests per second
RateLimitBurstint200Burst capacity
OperationTimeouttime.Duration30sPer-operation timeout

Option Helpers

FunctionDescription
WithDefault(name)Set the default backend name
WithBackend(name, backend)Add a single named backend
WithBackends(backends)Set all backends at once
WithLocalBackend(name, rootDir, baseURL)Add a local filesystem backend
WithS3Backend(name, bucket, region, endpoint)Add an S3 backend
WithPresignedURLs(enabled, expiry)Configure presigned URL generation
WithMaxUploadSize(size)Set maximum upload size
WithChunkSize(size)Set chunk size for multipart operations
WithCDN(enabled, baseURL)Configure CDN integration
WithResilience(resilience)Set resilience configuration
WithEnhancedBackend(enabled)Toggle enhanced local backend
WithRequireConfig(require)Require config from ConfigManager
WithConfig(config)Provide a complete config struct

How is this guide?

On this page