A high-performance, memory-safe HTTP/HTTPS proxy server in Go with comprehensive logging, monitoring, and flexible blocking capabilities.I've created a production-ready proxy server in Go with all the features you requested. Here's what it includes:
Memory Safety & Performance:
- Uses Go's built-in memory safety and garbage collection
- Atomic operations for thread-safe statistics
- Connection pooling and efficient I/O with
io.Copy - Configurable timeouts to prevent resource leaks
Logging & Monitoring:
- Dual logging (console + file)
- Real-time statistics (total requests, blocked requests, bandwidth)
- Periodic stats reporting (every 60 seconds by default)
- Detailed request logging with timestamps
Blocking System:
- Loads domains from
blacklist.txt - Supports wildcard blocking (blocks subdomains automatically)
- Thread-safe with RWMutex for concurrent access
- Ignores comments (lines starting with
#)
Deployment Ready:
- Graceful shutdown support
- Configurable via command-line flags
- Works for both HTTP and HTTPS (CONNECT tunneling)
- Can run locally or remotely
1. Create a blacklist.txt file:
# Social Media
facebook.com
twitter.com
instagram.com
# Ads
doubleclick.net
googleads.com
# Custom sites
example.com2. Run locally:
go run main.go3. Run with custom settings:
go run main.go -addr :3128 -blocklist custom-blocklist.txt -log /var/log/proxy.log -stats 5m4. Configure your browser/system to use the proxy:
- Host:
localhost(or your server IP) - Port:
8080(or your custom port)
5. For remote deployment:
# Build binary
CGO_ENABLED=0 go build -o go-proxy main.go
# Run on server
./go-proxy -addr :8080The server supports graceful shutdown (Ctrl+C), automatically handles both HTTP and HTTPS traffic, and provides real-time monitoring of all requests!