Skip to content

restuhaqza/go-proxy-server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

4 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ HTTP Proxy Server with Go

A high-performance HTTP/HTTPS proxy server written in Go with Basic Auth authentication and production-ready Docker deployment

Go Version License Docker GitHub Actions

A lightweight, secure, and easy-to-deploy proxy server perfect for development, testing, and production environments.


✨ Features

Feature Description
🌐 HTTP/HTTPS Proxy Full support for both HTTP and HTTPS protocols
πŸ” Basic Auth Secure username/password authentication for all requests
πŸ”— CONNECT Method Native support for HTTPS tunneling
βš™οΈ Environment Config Simple configuration via environment variables
🐳 Docker Ready Multi-stage Docker build for optimized images
πŸ’š Health Check Built-in health monitoring endpoint
πŸ“ Request Logging Detailed logging for monitoring and debugging
πŸ‘€ Non-root User Security-focused container running as non-root

πŸ“– Usage

πŸ–₯️ 1. Development (Local)

# Clone or download project
cd go-proxy-server

# Install dependencies
go mod tidy

# Set environment variables (optional)
export PROXY_USERNAME=admin
export PROXY_PASSWORD=mypassword
export PROXY_PORT=8080

# Run application
go run main.go

πŸ”¨ 2. Build Binary

# Build binary
go build -o proxy-server

# Run binary
./proxy-server

🐳 3. Docker Deployment

Using Docker Build

# Build Docker image
docker build -t go-proxy-server .

# Run container with default credentials
docker run -d \
  --name proxy-server \
  -p 8080:8080 \
  go-proxy-server

# Run container with custom credentials
docker run -d \
  --name proxy-server \
  -p 8080:8080 \
  -e PROXY_USERNAME=myuser \
  -e PROXY_PASSWORD=mypassword \
  go-proxy-server

Using Docker Compose

# Copy environment file
cp .env.example .env

# Edit .env file with desired credentials
nano .env

# Start with docker-compose
docker-compose up -d

# View logs
docker-compose logs -f

# Stop
docker-compose down

βš™οΈ Configuration

The application uses environment variables for configuration:

Variable Default Description
PROXY_USERNAME admin Username for proxy authentication
PROXY_PASSWORD password123 Password for proxy authentication
PROXY_PORT 8080 Proxy server port

πŸ”Œ How to Use Proxy

🌍 1. Configure Proxy in Browser/Application

Setting Value
Proxy Type HTTP
Server localhost (or your server IP)
Port 8080 (or your configured port)
Username As per PROXY_USERNAME
Password As per PROXY_PASSWORD

πŸ§ͺ 2. Test with curl

# Test HTTP request
curl -v \
  --proxy http://admin:mypassword@localhost:8080 \
  http://httpbin.org/ip

# Test HTTPS request
curl -v \
  --proxy http://admin:mypassword@localhost:8080 \
  https://httpbin.org/ip

πŸ“₯ 3. Test with wget

# Set proxy environment
export http_proxy=http://admin:mypassword@localhost:8080
export https_proxy=http://admin:mypassword@localhost:8080

# Test request
wget http://httpbin.org/ip

πŸ“Š Monitoring

πŸ₯ Health Check

The application has a built-in health check that can be used for monitoring:

# Check health (for monitoring only, not for proxy)
curl http://localhost:8080

πŸ“‹ Logs

The application will display logs for each request:

2024/01/01 12:00:00 127.0.0.1:12345 GET http://example.com
2024/01/01 12:00:01 127.0.0.1:12346 CONNECT example.com:443

πŸ”’ Security

Security Feature Description
πŸ” Basic Auth Authentication required for all requests
πŸ‘€ Non-root User Container runs as non-root user
πŸ”οΈ Alpine Linux Minimal, secure base image
πŸ“¦ No Extra Packages Only necessary dependencies installed

πŸ› οΈ Troubleshooting

❌ Error "Proxy Authentication Required"

Solution: Make sure the username and password used match the server configuration.

⏱️ Connection Timeout

Solution: The application has a 30-second timeout for each request. For longer requests, adjust the timeout in the code.

πŸ”Œ Port Already in Use

Solution: Change the port in the PROXY_PORT environment variable or use a different port when running the container.


πŸ”„ CI/CD and Versioning

πŸ€– GitHub Actions Workflows

This project is equipped with GitHub Actions workflows for automation:

1. CI/CD Pipeline (ci-cd.yml)

  • Trigger: Push to main/develop, Pull Request, or Tag
  • Process:
    • βœ… Test and build application
    • βœ… Security scan with staticcheck
    • βœ… Build multi-platform Docker images
    • βœ… Push to GitHub Container Registry
    • βœ… Vulnerability scan with Trivy

2. Release Pipeline (release.yml)

  • Trigger: Push tag with format v* (example: v1.0.0)
  • Process:
    • βœ… Build binary for multiple platforms (Linux, macOS, Windows)
    • βœ… Create checksums
    • βœ… Build and push Docker images
    • βœ… Create GitHub release with binaries
    • βœ… Generate automatic release notes

3. Security Scan (security.yml)

  • Trigger: Daily schedule or manual
  • Process:
    • βœ… Dependency scanning with Gosec
    • βœ… Container vulnerability scanning
    • βœ… Upload results to GitHub Security tab

4. Docker Hub Release (dockerhub.yml)

  • Trigger: Push tag v* or manual
  • Process:
    • βœ… Build and push to Docker Hub
    • βœ… Update description automatically

πŸ”‘ Setup GitHub Repository

  1. Required Secrets:
# For Docker Hub (optional)
DOCKERHUB_USERNAME=your-dockerhub-username
DOCKERHUB_TOKEN=your-dockerhub-access-token
  1. Branch Protection Rules (Recommended):
    • Require pull request reviews
    • Require status checks (CI tests)
    • Require branches to be up to date

πŸ“¦ Versioning and Release

Using Release Script

# Patch release (1.0.0 -> 1.0.1)
./scripts/release.sh patch

# Minor release (1.0.1 -> 1.1.0)
./scripts/release.sh minor

# Major release (1.1.0 -> 2.0.0)
./scripts/release.sh major

Manual Release

# Create and push tag
git tag -a v1.0.0 -m "Release v1.0.0"
git push origin v1.0.0

# GitHub Actions will automatically:
# - Build application for multiple platforms
# - Create Docker images
# - Create GitHub release
# - Generate release notes

πŸ‹ Registry Images

GitHub Container Registry

# Pull latest
docker pull ghcr.io/your-username/go-proxy-server:latest

# Pull specific version
docker pull ghcr.io/your-username/go-proxy-server:v1.0.0

Docker Hub (optional)

# Pull latest
docker pull your-username/go-proxy-server:latest

# Pull specific version
docker pull your-username/go-proxy-server:v1.0.0

πŸ’» Development

πŸš€ Quick Setup

# Setup development environment
./scripts/setup-dev.sh

# Install git hooks, dependencies, and tools

πŸ“ Project Structure

go-proxy-server/
β”œβ”€β”€ .github/
β”‚   β”œβ”€β”€ workflows/           # GitHub Actions workflows
β”‚   β”‚   β”œβ”€β”€ ci-cd.yml       # Main CI/CD pipeline
β”‚   β”‚   β”œβ”€β”€ release.yml     # Release automation
β”‚   β”‚   β”œβ”€β”€ security.yml    # Security scanning
β”‚   β”‚   └── dockerhub.yml   # Docker Hub publishing
β”‚   β”œβ”€β”€ ISSUE_TEMPLATE/     # Issue templates
β”‚   β”œβ”€β”€ dependabot.yml     # Dependency updates
β”‚   └── pull_request_template.md
β”œβ”€β”€ scripts/
β”‚   β”œβ”€β”€ release.sh          # Release automation script
β”‚   └── setup-dev.sh        # Development setup
β”œβ”€β”€ main.go                 # Main application
β”œβ”€β”€ go.mod                  # Go modules
β”œβ”€β”€ Dockerfile              # Docker configuration
β”œβ”€β”€ docker-compose.yml      # Docker Compose
β”œβ”€β”€ .env.example            # Environment example
β”œβ”€β”€ .gitignore             # Git ignore
└── README.md              # Documentation

πŸ”„ Development Workflow

1. Setup environment

./scripts/setup-dev.sh

2. Create feature branch

git checkout -b feature/your-feature

3. Development

# Run locally
go run main.go

# Or with Docker
docker-compose up --build

4. Testing

# Run tests
go test ./...

# Run linting
staticcheck ./...
golangci-lint run

5. Commit and Push

git add .
git commit -m "feat: add your feature"
git push origin feature/your-feature

6. Create Pull Request

  • GitHub will automatically run CI checks
  • Review and merge to main

7. Release

# After merge to main
git checkout main
git pull origin main
./scripts/release.sh patch  # or minor/major

πŸ” Monitoring and Maintenance

Feature Description
πŸ€– Dependabot Automatically updates dependencies every Monday
πŸ”’ Security Scans Run daily for vulnerability detection
πŸ’š Health Checks Built-in health check in container
πŸ“ Logging Request logging for monitoring

βž• Adding Features

  1. Edit main.go to add new logic
  2. Add tests if needed
  3. Update documentation in README.md
  4. Create Pull Request with clear description

πŸ“„ License

License: MIT

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


Made with ❀️ using Go

⬆ Back to Top

About

A http proxy to forward your request via egress

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages