反向代理可以整体设置源站默认超时时间等参数
This commit is contained in:
@@ -13,20 +13,20 @@ import (
|
||||
// 源站服务配置
|
||||
type OriginConfig struct {
|
||||
Id int64 `yaml:"id" json:"id"` // ID
|
||||
IsOn bool `yaml:"isOn" json:"isOn"` // 是否启用 TODO
|
||||
IsOn bool `yaml:"isOn" json:"isOn"` // 是否启用
|
||||
Version int `yaml:"version" json:"version"` // 版本
|
||||
Name string `yaml:"name" json:"name"` // 名称 TODO
|
||||
Name string `yaml:"name" json:"name"` // 名称
|
||||
Addr *NetworkAddressConfig `yaml:"addr" json:"addr"` // 地址
|
||||
Description string `yaml:"description" json:"description"` // 描述 TODO
|
||||
Code string `yaml:"code" json:"code"` // 代号 TODO
|
||||
|
||||
Weight uint `yaml:"weight" json:"weight"` // 权重 TODO
|
||||
ConnTimeout *shared.TimeDuration `yaml:"failTimeout" json:"failTimeout"` // 连接失败超时 TODO
|
||||
ReadTimeout *shared.TimeDuration `yaml:"readTimeout" json:"readTimeout"` // 读取超时时间 TODO
|
||||
IdleTimeout *shared.TimeDuration `yaml:"idleTimeout" json:"idleTimeout"` // 空闲连接超时时间 TODO
|
||||
Weight uint `yaml:"weight" json:"weight"` // 权重
|
||||
ConnTimeout *shared.TimeDuration `yaml:"connTimeout" json:"connTimeout"` // 连接失败超时
|
||||
ReadTimeout *shared.TimeDuration `yaml:"readTimeout" json:"readTimeout"` // 读取超时时间
|
||||
IdleTimeout *shared.TimeDuration `yaml:"idleTimeout" json:"idleTimeout"` // 空闲连接超时时间
|
||||
MaxFails int `yaml:"maxFails" json:"maxFails"` // 最多失败次数 TODO
|
||||
MaxConns int `yaml:"maxConns" json:"maxConns"` // 最大并发连接数 TODO
|
||||
MaxIdleConns int `yaml:"idleConns" json:"idleConns"` // 最大空闲连接数 TODO
|
||||
MaxConns int `yaml:"maxConns" json:"maxConns"` // 最大并发连接数
|
||||
MaxIdleConns int `yaml:"idleConns" json:"idleConns"` // 最大空闲连接数
|
||||
|
||||
StripPrefix string `yaml:"stripPrefix" json:"stripPrefix"` // 去除URL前缀
|
||||
RequestURI string `yaml:"requestURI" json:"requestURI"` // 转发后的请求URI TODO
|
||||
@@ -39,14 +39,14 @@ type OriginConfig struct {
|
||||
|
||||
// 健康检查URL,目前支持:
|
||||
// - http|https 返回2xx-3xx认为成功
|
||||
HealthCheck *HealthCheckConfig `yaml:"healthCheck" json:"healthCheck"`
|
||||
HealthCheck *HealthCheckConfig `yaml:"healthCheck" json:"healthCheck"` // TODO
|
||||
|
||||
CertRef *sslconfigs.SSLCertRef `yaml:"certRef" json:"certRef"` // 证书的引用
|
||||
Cert *sslconfigs.SSLCertConfig `yaml:"cert" json:"cert"` // 请求源服务器用的证书
|
||||
CertRef *sslconfigs.SSLCertRef `yaml:"certRef" json:"certRef"` // 证书的引用 TODO
|
||||
Cert *sslconfigs.SSLCertConfig `yaml:"cert" json:"cert"` // 请求源服务器用的证书 TODO
|
||||
|
||||
// ftp
|
||||
FTPServerRef *FTPServerRef `yaml:"ftpServerRef" json:"ftpServerRef"`
|
||||
FTPServer *FTPServerConfig `yaml:"ftpServer" json:"ftpServer"`
|
||||
FTPServerRef *FTPServerRef `yaml:"ftpServerRef" json:"ftpServerRef"` // TODO
|
||||
FTPServer *FTPServerConfig `yaml:"ftpServer" json:"ftpServer"` // TODO
|
||||
|
||||
connTimeoutDuration time.Duration
|
||||
readTimeoutDuration time.Duration
|
||||
@@ -90,7 +90,7 @@ func (this *OriginConfig) Init() error {
|
||||
}
|
||||
}
|
||||
|
||||
// failTimeout
|
||||
// connTimeout
|
||||
if this.ConnTimeout != nil {
|
||||
this.connTimeoutDuration = this.ConnTimeout.Duration()
|
||||
}
|
||||
|
||||
@@ -26,6 +26,13 @@ type ReverseProxyConfig struct {
|
||||
BackupOriginRefs []*OriginRef `yaml:"backupOriginRefs" json:"backupOriginRefs"` // 备用源站引用
|
||||
Scheduling *SchedulingConfig `yaml:"scheduling" json:"scheduling"` // 调度算法选项
|
||||
|
||||
ConnTimeout *shared.TimeDuration `yaml:"connTimeout" json:"connTimeout"` // 连接失败超时 TODO
|
||||
ReadTimeout *shared.TimeDuration `yaml:"readTimeout" json:"readTimeout"` // 读取超时时间 TODO
|
||||
IdleTimeout *shared.TimeDuration `yaml:"idleTimeout" json:"idleTimeout"` // 空闲连接超时时间 TODO
|
||||
MaxFails int `yaml:"maxFails" json:"maxFails"` // 最多失败次数 TODO
|
||||
MaxConns int `yaml:"maxConns" json:"maxConns"` // 最大并发连接数 TODO
|
||||
MaxIdleConns int `yaml:"maxIdleConns" json:"maxIdleConns"` // 最大空闲连接数 TODO
|
||||
|
||||
StripPrefix string `yaml:"stripPrefix" json:"stripPrefix"` // 去除URL前缀
|
||||
RequestHostType RequestHostType `yaml:"requestHostType" json:"requestHostType"` // 请求Host类型
|
||||
RequestHost string `yaml:"requestHost" json:"requestHost"` // 请求Host,支持变量
|
||||
@@ -60,17 +67,33 @@ func (this *ReverseProxyConfig) Init() error {
|
||||
this.hasPrimaryOrigins = len(this.PrimaryOrigins) > 0
|
||||
this.hasBackupOrigins = len(this.BackupOrigins) > 0
|
||||
|
||||
for _, origin := range this.PrimaryOrigins {
|
||||
err := origin.Init()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
for _, origins := range [][]*OriginConfig{this.PrimaryOrigins, this.BackupOrigins} {
|
||||
for _, origin := range origins {
|
||||
// 覆盖参数设置
|
||||
if origin.MaxFails <= 0 && this.MaxFails > 0 {
|
||||
origin.MaxFails = this.MaxFails
|
||||
}
|
||||
if origin.MaxConns <= 0 && this.MaxConns > 0 {
|
||||
origin.MaxConns = this.MaxConns
|
||||
}
|
||||
if origin.MaxIdleConns <= 0 && this.MaxIdleConns > 0 {
|
||||
origin.MaxIdleConns = this.MaxIdleConns
|
||||
}
|
||||
if (origin.ConnTimeout == nil || origin.ConnTimeout.Count <= 0) && this.ConnTimeout != nil && this.ConnTimeout.Count > 0 {
|
||||
origin.ConnTimeout = this.ConnTimeout
|
||||
}
|
||||
if (origin.ReadTimeout == nil || origin.ReadTimeout.Count <= 0) && this.ReadTimeout != nil && this.ReadTimeout.Count > 0 {
|
||||
origin.ReadTimeout = this.ReadTimeout
|
||||
}
|
||||
if (origin.IdleTimeout == nil || origin.IdleTimeout.Count <= 0) && this.IdleTimeout != nil && this.IdleTimeout.Count > 0 {
|
||||
origin.IdleTimeout = this.IdleTimeout
|
||||
}
|
||||
|
||||
for _, origin := range this.BackupOrigins {
|
||||
err := origin.Init()
|
||||
if err != nil {
|
||||
return err
|
||||
// 初始化
|
||||
err := origin.Init()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user