This commit is contained in:
2025-03-14 18:50:49 +00:00
commit 1a53a9a8f3
90 changed files with 13116 additions and 0 deletions

View File

@@ -0,0 +1,35 @@
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
// 启用一些基本功能
cfg.PreserveClientIP = true // 保留客户端IP
cfg.AddXForwardedFor = true // 添加X-Forwarded-For头
// 创建代理实例
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)
}
}