Files
goproxy/internal/config/config.go
2025-03-13 15:56:33 +08:00

136 lines
3.5 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package config
import (
"time"
)
// Config 代理配置
type Config struct {
// 监听地址
ListenAddr string
// 是否启用负载均衡
EnableLoadBalancing bool
// 负载均衡后端列表
Backends []string
// 是否启用限流
EnableRateLimit bool
// 每秒请求速率限制
RateLimit float64
// 并发请求峰值限制
MaxBurst int
// 最大连接数
MaxConnections int
// 是否启用连接池
EnableConnectionPool bool
// 连接池大小
ConnectionPoolSize int
// 连接空闲超时时间
IdleTimeout time.Duration
// 请求超时时间
RequestTimeout time.Duration
// 是否启用响应缓存
EnableCache bool
// 缓存过期时间
CacheTTL time.Duration
// 是否启用HTTPS解密
DecryptHTTPS bool
// TLS证书文件路径
TLSCert string
// TLS密钥文件路径
TLSKey string
// CA证书文件路径(用于生成动态证书)
CACert string
// CA密钥文件路径(用于生成动态证书)
CAKey string
// 是否启用健康检查
EnableHealthCheck bool
// 健康检查间隔时间
HealthCheckInterval time.Duration
// 健康检查超时时间
HealthCheckTimeout time.Duration
// 是否启用重试机制
EnableRetry bool
// 最大重试次数
MaxRetries int
// 重试间隔基数
RetryBackoff time.Duration
// 最大重试间隔
MaxRetryBackoff time.Duration
// 是否启用监控指标
EnableMetrics bool
// 是否启用请求追踪
EnableTracing bool
// 是否拦截WebSocket
WebSocketIntercept bool
// DNS缓存过期时间
DNSCacheTTL time.Duration
// 是否作为反向代理
ReverseProxy bool
// 反向代理规则文件路径
ReverseProxyRulesFile string
// 是否启用URL重写
EnableURLRewrite bool
// 是否保留客户端IP
PreserveClientIP bool
// 是否启用压缩
EnableCompression bool
// 是否自动添加CORS头
EnableCORS bool
// 重写Host头
RewriteHostHeader bool
// 是否添加X-Forwarded-For头
AddXForwardedFor bool
// 是否添加X-Real-IP头
AddXRealIP bool
// 是否支持Websocket升级
SupportWebSocketUpgrade bool
// 是否使用ECDSA生成证书默认使用RSA
UseECDSA bool
}
// DefaultConfig 默认配置
func DefaultConfig() *Config {
return &Config{
ListenAddr: ":8080",
EnableLoadBalancing: false,
Backends: []string{},
EnableRateLimit: false,
RateLimit: 100,
MaxBurst: 50,
MaxConnections: 1000,
EnableConnectionPool: true,
ConnectionPoolSize: 100,
IdleTimeout: 60 * time.Second,
RequestTimeout: 30 * time.Second,
EnableCache: false,
CacheTTL: 5 * time.Minute,
DecryptHTTPS: false,
TLSCert: "",
TLSKey: "",
CACert: "",
CAKey: "",
EnableHealthCheck: false,
HealthCheckInterval: 10 * time.Second,
HealthCheckTimeout: 5 * time.Second,
EnableRetry: true,
MaxRetries: 3,
RetryBackoff: 100 * time.Millisecond,
MaxRetryBackoff: 2 * time.Second,
EnableMetrics: false,
EnableTracing: false,
WebSocketIntercept: false,
DNSCacheTTL: 5 * time.Minute,
ReverseProxy: false,
ReverseProxyRulesFile: "",
EnableURLRewrite: false,
PreserveClientIP: true,
EnableCompression: false,
EnableCORS: false,
RewriteHostHeader: false,
AddXForwardedFor: true,
AddXRealIP: true,
SupportWebSocketUpgrade: true,
UseECDSA: false,
}
}