This commit is contained in:
2025-03-15 10:17:07 +00:00
parent 1a53a9a8f3
commit 78f5fbf51a
24 changed files with 2915 additions and 282 deletions

View File

@@ -0,0 +1,40 @@
package main
import (
"fmt"
"log"
"net/http"
"github.com/darkit/goproxy"
"github.com/darkit/goproxy/config"
)
func main() {
// 创建基本配置
cfg := config.DefaultConfig()
// 配置反向代理
cfg.ReverseProxy = true // 启用反向代理模式
cfg.ListenAddr = ":8080" // 监听本地8080端口
cfg.TargetAddr = "http://example.com" // 转发到example.com
// 设置HTTP头部选项
cfg.PreserveClientIP = true // 保留客户端IP
cfg.AddXForwardedFor = true // 添加X-Forwarded-For头
cfg.AddXRealIP = true // 添加X-Real-IP头
// 设置性能选项
cfg.EnableCompression = true // 启用压缩
cfg.EnableCache = true // 启用缓存
// 创建代理实例
proxy := goproxy.New(&goproxy.Options{
Config: cfg,
})
// 启动服务器
fmt.Println("反向代理启动在 :8080转发到 http://example.com")
if err := http.ListenAndServe(":8080", proxy); err != nil {
log.Fatalf("服务器启动失败: %v", err)
}
}