Help us shape the future of Go! Take the 2026 Go Developer Survey

dug

module
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 6, 2026 License: MIT

README ΒΆ

DUG (Distributed Unified Gateway)

Go Reference Release Go Version License Stars

A lightweight, production-inspired API Gateway built from scratch in Go.

Build. Learn. Route.

DUG is an API Gateway designed to understand how modern gateways like NGINX, Traefik, Envoy, and Kong work internally by implementing their core building blocks from first principles.

Rather than wrapping existing gateway libraries, DUG focuses on building the networking, reliability, and traffic management components yourself to gain a deeper understanding of production backend infrastructure.


✨ Features

🚦 Traffic Management

  • βœ… Reverse Proxy
  • βœ… Route-based Routing
  • βœ… YAML Configuration
  • βœ… Graceful Shutdown
  • βœ… WebSocket Proxy
  • βœ… Dynamic Configuration Reload

βš–οΈ Load Balancing

  • βœ… Round Robin
  • βœ… Smooth Weighted Round Robin (SWRR)
  • βœ… Least Connections

πŸ›‘ Reliability

  • βœ… Retry Mechanism
  • βœ… Exponential Backoff
  • βœ… Active Health Checks
  • βœ… Passive Health Checks
  • βœ… Circuit Breaker
  • βœ… Request Timeouts

πŸ”’ Security & Traffic Control

  • βœ… HTTPS / TLS
  • βœ… Per-IP Rate Limiting
  • βœ… CORS
  • βœ… Request Header Manipulation
  • βœ… Response Header Manipulation
  • βœ… Security Headers
  • βœ… Request Body Size Limit
  • βœ… Gzip Response Compression

πŸ“Š Observability

  • βœ… Prometheus Metrics
  • βœ… Structured Logging (slog)
  • βœ… Request IDs

πŸ” Service Discovery

  • βœ… Static Service Discovery
  • βœ… DNS Service Discovery

βš™οΈ Configuration

  • βœ… YAML Configuration
  • βœ… Hot Configuration Reload
  • βœ… Atomic Router Reload

πŸ— Architecture

                     Client
                        β”‚
                 HTTP / HTTPS
                        β”‚
                        β–Ό
              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
              β”‚        DUG         β”‚
              β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
              β”‚ Reverse Proxy      β”‚
              β”‚ Router             β”‚
              β”‚ Load Balancer      β”‚
              β”‚ Retry Engine       β”‚
              β”‚ Health Checks      β”‚
              β”‚ Circuit Breaker    β”‚
              β”‚ Rate Limiter       β”‚
              β”‚ Header Middleware  β”‚
              β”‚ Service Discovery  β”‚
              β”‚ Metrics            β”‚
              β”‚ Logging            β”‚
              β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                        β”‚
        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
        β–Ό               β–Ό               β–Ό
    Backend A       Backend B       Backend C

πŸš€ Getting Started

Install

go install github.com/khareutkarshk/dug/cmd/dug@latest

Ensure $(go env GOPATH)/bin is on your PATH, then verify:

dug version
Option 2 β€” Build from source
git clone https://github.com/khareutkarshk/dug.git
cd dug
go mod tidy
make build
./dug version
Option 3 β€” Docker

Local compose:

docker compose up --build

Or pull a published release image from GitHub Container Registry:

docker pull ghcr.io/khareutkarshk/dug:latest
docker run --rm -p 8080:8080 ghcr.io/khareutkarshk/dug:v0.1.0

Generate local TLS certificates

mkdir -p certs

openssl req -x509 \
-newkey rsa:4096 \
-keyout certs/server.key \
-out certs/server.crt \
-days 365 \
-nodes

Start the gateway

dug run -config configs/edge.yaml

Or from source without installing:

go run ./cmd/dug run -config configs/edge.yaml

🧰 CLI

DUG ships as a multi-command CLI:

Command Description
dug init Bootstrap a new DUG project
dug run Start the gateway
dug validate Validate a configuration file
dug doctor Check config, port availability, TLS files, and upstreams
dug version Print build metadata
dug help Show usage
# Bootstrap a project
dug init my-gateway
cd my-gateway
dug run -config configs/edge.yaml

# Start gateway
dug run -config configs/edge.yaml

# Validate config before deploy
dug validate -config configs/edge.yaml
dug validate -config configs/edge.yaml -quiet   # CI-friendly
dug validate -config configs/edge.yaml -json    # machine-readable

# Local diagnostics (non-zero exit if checks fail)
dug doctor -config configs/edge.yaml
dug doctor -config configs/edge.yaml -timeout 2s -json

# Version (human, short, machine-readable)
dug version
dug version -short
dug version -json
Releases

Pushing a version tag (v*) runs .github/workflows/release.yml, which:

  1. Cross-compiles binaries (linux/darwin/windows) with version ldflags
  2. Packages them (.tar.gz / .zip) and publishes a GitHub Release
  3. Builds and pushes a multi-arch image to GHCR (linux/amd64, linux/arm64)
# Binary (archive contains ./dug)
curl -LO https://github.com/khareutkarshk/dug/releases/latest/download/dug_v0.1.0_linux_amd64.tar.gz
tar -xzf dug_v0.1.0_linux_amd64.tar.gz
./dug version

# Container
docker pull ghcr.io/khareutkarshk/dug:v0.1.0
docker pull ghcr.io/khareutkarshk/dug:latest

To cut a release from main:

git tag v0.1.1
git push origin v0.1.1

βš™οΈ Configuration

DUG is configured using a YAML file.

Configuration supports:

  • Routes
  • Multiple upstreams
  • Load balancing strategy
  • Retry policy
  • Health checks
  • Timeouts
  • HTTPS / TLS
  • CORS
  • Request & Response Headers
  • Rate Limiting
  • Service Discovery

Example configuration:

server:
  port: 8080

routes:
  - path: /
    upstreams:
      - url: http://localhost:3001
        weight: 1

Default configuration:

configs/edge.yaml

πŸ“ Project Structure

.
β”œβ”€β”€ cmd/
β”‚   └── dug/          # CLI entrypoint (run, validate, doctor, version, init)
β”œβ”€β”€ configs/
β”œβ”€β”€ examples/
β”‚   β”œβ”€β”€ README.md             # Example catalog
β”‚   β”œβ”€β”€ backend/              # Legacy demo upstream :3001
β”‚   β”œβ”€β”€ backend2/             # Legacy demo upstream :3002
β”‚   β”œβ”€β”€ echo/                 # Shared configurable mock upstream
β”‚   β”œβ”€β”€ basic-reverse-proxy/
β”‚   β”œβ”€β”€ docker-compose/
β”‚   β”œβ”€β”€ microservices/
β”‚   β”œβ”€β”€ nextjs-api/
β”‚   β”œβ”€β”€ ai-gateway/
β”‚   β”œβ”€β”€ blue-green/
β”‚   └── websocket/
β”œβ”€β”€ benchmarks/
β”œβ”€β”€ internal/
β”‚   β”œβ”€β”€ app/
β”‚   β”œβ”€β”€ cli/
β”‚   β”œβ”€β”€ config/
β”‚   β”œβ”€β”€ discovery/
β”‚   β”œβ”€β”€ httpx/
β”‚   β”œβ”€β”€ logger/
β”‚   β”œβ”€β”€ metrics/
β”‚   β”œβ”€β”€ middleware/
β”‚   β”œβ”€β”€ proxy/
β”‚   β”œβ”€β”€ ratelimit/
β”‚   β”œβ”€β”€ router/
β”‚   β”œβ”€β”€ server/
β”‚   β”œβ”€β”€ upstream/
β”‚   └── version/
β”œβ”€β”€ test/
└── README.md

See examples/README.md for runnable demos (load balancing, path routing, Next.js, AI gateway, blue/green).


πŸ§ͺ Testing

Run all tests

go test ./...

Run with race detector

go test ./... -race

Generate coverage

go test ./... -cover

πŸ“ˆ Current Status

DUG currently includes:

  • Reverse Proxy
  • Route-based Routing
  • Multiple Load Balancing Algorithms
  • Retry Engine
  • Circuit Breaker
  • Active & Passive Health Checks
  • HTTPS
  • WebSocket Proxy
  • Dynamic Configuration Reload
  • DNS Service Discovery
  • Rate Limiting
  • Header Manipulation
  • Prometheus Metrics
  • Structured Logging
  • Request IDs

The core gateway functionality is complete and stable. The next milestone focuses on improving developer experience, packaging, and documentation.


πŸ›£ Roadmap

v1.0 β€” Developer Experience

CLI
  • dug init
  • dug run
  • dug validate
  • dug doctor
  • dug version (-short, -json)
Distribution
  • Docker Image
  • GitHub Releases (tag v* workflow)
  • Pre-built binaries
  • go install support
Documentation
  • Installation Guide
  • Configuration Reference
  • Feature Documentation
  • Example Configurations
CI/CD
  • GitHub Actions
  • Go Race Tests
  • golangci-lint
  • Automated Releases (binaries + GHCR)

Future

  • JWT Authentication
  • API Keys
  • OpenTelemetry
  • Response Caching
  • HTTP/2
  • HTTP/3
  • Kubernetes Service Discovery
  • Consul Service Discovery
  • Canary Routing
  • Blue-Green Deployments
  • Plugin System

πŸ’‘ Why DUG?

DUG started as a way to learn Go by building production-inspired backend infrastructure instead of another CRUD application.

Every major component is implemented from scratch to understand:

  • Reverse proxies
  • Load balancing algorithms
  • Circuit breakers
  • Retry strategies
  • Health checking
  • Service discovery
  • Concurrent programming
  • High-performance HTTP servers
  • Production networking patterns

The name is inspired by Dug 🐢, the lovable golden retriever from Pixar's Up.

While DUG began as a learning project, it has evolved into a fully functional API Gateway that continues to grow with production-inspired features.


🀝 Contributing

Contributions, bug reports, ideas, and discussions are always welcome.

If you'd like to contribute:

  1. Fork the repository
  2. Create a feature branch
  3. Commit your changes
  4. Open a Pull Request

⭐ Support

If you found DUG useful or interesting, consider giving the repository a Star.

It helps others discover the project and motivates future development.


πŸ“„ License

This project is licensed under the MIT License. See the LICENSE file for details.

Directories ΒΆ

Path Synopsis
Package benchmarks contains an optional gateway load-benchmark suite.
Package benchmarks contains an optional gateway load-benchmark suite.
cmd
dug command
examples
backend command
backend2 command
echo command
websocket command
internal
app
cli
test

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL