A high-performance, feature-rich HTTP proxy server implemented in Go.
- ✨ SSL Termination
- 🔄 Connection Management
- 🔒 Circuit Breaker Pattern
- 📝 Request/Response Logging
- 🚦 Rate Limiting
- 💾 Caching Support
- 🔍 Health Checking
- 📊 Metrics Collection
- 🔄 Protocol Upgrade/Downgrade
- 🛡️ Security Features
go get github.com/yourusername/proxy
package main
import (
"log"
"github.com/yourusername/proxy/internal/config"
"github.com/yourusername/proxy/internal/proxy"
)
func main() {
cfg := &config.Config{
Server: config.ServerConfig{
Port: 8080,
},
Services: map[string]config.ServiceConfig{
"api": {
URL: "http://api.example.com",
},
},
}
proxy, err := proxy.New(cfg)
if err != nil {
log.Fatal(err)
}
log.Fatal(proxy.Start())
}
The proxy server can be configured using YAML:
server:
port: 8080
readTimeout: 30s
writeTimeout: 30s
cache:
enabled: true
ttl: 5m
circuitBreaker:
maxFailures: 5
timeout: 10s
services:
api:
url: http://api.example.com
timeout: 30s
rateLimit:
rate: 100
burst: 10
Protects backend services from cascading failures:
breaker := circuitbreaker.New("service", 5, time.Second)
handler := breaker.Wrap(backendHandler)
Efficient caching of responses:
cache := cache.New(5 * time.Minute)
cached, hit := cache.Get(request)
if hit {
return cached
}
Regular health checks of backend services:
checker := health.NewChecker(map[string]string{
"service1": "http://service1/health",
}, time.Minute)
checker.Start()
Easy to add custom middleware:
proxy.Use(
middleware.NewRateLimit(100, 10),
middleware.NewAuth(authValidator),
middleware.NewLogging(nil),
)
Benchmark results:
BenchmarkProxy/DirectProxy-8 10000 112340 ns/op
BenchmarkProxy/WithCache-8 50000 31245 ns/op
BenchmarkProxy/WithCircuitBreaker-8 20000 89123 ns/op
BenchmarkProxy/FullStack-8 10000 156789 ns/op
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing
) - Commit your changes (
git commit -am 'Add amazing feature'
) - Push to the branch (
git push origin feature/amazing
) - Create a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Gorilla Mux for routing
- OpenTracing for distributed tracing
- Prometheus for metrics
- GitHub: @oabraham1
- Twitter: @ojima_abraham