Gateway

Configuration

Config reference, YAML example, and options for Gateway

YAML Configuration Example

config.yaml
extensions:
  gateway:
    enabled: true
    basePath: ""

    timeouts:
      connect: "10s"
      read: "30s"
      write: "30s"
      idle: "90s"

    retry:
      enabled: true
      maxAttempts: 3
      initialDelay: "100ms"
      maxDelay: "5s"
      jitter: true

    circuitBreaker:
      enabled: true
      failureThreshold: 5
      failureWindow: "60s"
      resetTimeout: "30s"

    healthCheck:
      enabled: true
      interval: "10s"
      path: "/_/health"
      failureThreshold: 3
      successThreshold: 2

    loadBalancing:
      strategy: "round_robin"       # round_robin, weighted, random, least_connections, consistent_hash

    discovery:
      enabled: true
      pollInterval: "30s"
      watchMode: true
      autoPrefix: true
      prefixTemplate: "/{{.ServiceName}}"
      stripPrefix: true

    dashboard:
      enabled: true
      basePath: "/gateway"
      realtime: true

    openAPI:
      enabled: true
      path: "/gateway/openapi.json"
      uiPath: "/gateway/docs"

    routes:
      - path: "/api/users/*"
        target: "http://users-service:8080"
        methods: ["GET", "POST", "PUT", "DELETE"]
        stripPrefix: true

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

Programmatic Configuration

ext := gateway.NewExtension(
    gateway.WithDiscovery(true),
    gateway.WithDashboard(true),
    gateway.WithLoadBalancing("round_robin"),
    gateway.WithCircuitBreaker(true, 5, 60*time.Second, 30*time.Second),
    gateway.WithHealthCheck(true, 10*time.Second, "/_/health"),
)

Key Config Sections

Timeouts

FieldDefaultDescription
Connect10sUpstream connection timeout
Read30sResponse read timeout
Write30sRequest write timeout
Idle90sIdle connection timeout

Retry

FieldDefaultDescription
EnabledtrueEnable retries
MaxAttempts3Maximum retry attempts
InitialDelay100msInitial backoff delay
MaxDelay5sMaximum backoff delay
JittertrueAdd random jitter

Circuit Breaker

FieldDefaultDescription
EnabledtrueEnable circuit breakers
FailureThreshold5Failures before opening
FailureWindow60sWindow for counting failures
ResetTimeout30sTime before half-open

Discovery

FieldDefaultDescription
EnabledtrueEnable FARP auto-discovery
PollInterval30sDiscovery poll interval
WatchModetrueWatch for service changes
AutoPrefixtrueAuto-prefix routes with service name
PrefixTemplate"/{{.ServiceName}}"Route prefix template
StripPrefixtrueStrip prefix before forwarding

Dashboard

FieldDefaultDescription
EnabledtrueEnable admin dashboard
BasePath"/gateway"Dashboard URL base path
RealtimetrueEnable WebSocket updates

How is this guide?

On this page