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

dug

module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 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

πŸ“Š 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
docker compose up --build

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 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
# 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

Tagged versions (v*) publish multi-platform binaries via GitHub Releases:

  • linux/amd64, linux/arm64
  • darwin/amd64, darwin/arm64
  • windows/amd64
# Example after a release is published
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_v0.1.0_linux_amd64 version

βš™οΈ 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)
β”œβ”€β”€ configs/
β”œβ”€β”€ examples/
β”‚   β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ backend2/
β”‚   └── websocket/
β”œβ”€β”€ internal/
β”‚   β”œβ”€β”€ app/
β”‚   β”œβ”€β”€ cli/          # CLI command implementations
β”‚   β”œβ”€β”€ config/
β”‚   β”œβ”€β”€ discovery/
β”‚   β”œβ”€β”€ httpx/
β”‚   β”œβ”€β”€ logger/
β”‚   β”œβ”€β”€ metrics/
β”‚   β”œβ”€β”€ middleware/
β”‚   β”œβ”€β”€ proxy/
β”‚   β”œβ”€β”€ ratelimit/
β”‚   β”œβ”€β”€ router/
β”‚   β”œβ”€β”€ server/
β”‚   β”œβ”€β”€ upstream/
β”‚   └── version/      # Build-time version metadata
β”œβ”€β”€ test/
└── README.md

πŸ§ͺ 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 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

Future

  • JWT Authentication
  • API Keys
  • OpenTelemetry
  • Response Compression
  • 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
cmd
dug command
examples
backend command
backend2 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