Przeglądaj źródła

增加http参数配置

qdy 3 miesięcy temu
rodzic
commit
ceb875abf2
1 zmienionych plików z 32 dodań i 0 usunięć
  1. 32
    0
      config/config.go

+ 32
- 0
config/config.go Wyświetl plik

16
 	Doris    DorisConfig `yaml:"doris"`
16
 	Doris    DorisConfig `yaml:"doris"`
17
 	Auth     Auth        `yaml:"auth"`
17
 	Auth     Auth        `yaml:"auth"`
18
 	Service  Service     `yaml:"service"`
18
 	Service  Service     `yaml:"service"`
19
+	HTTP     HTTPConfig  `yaml:"http"` // 新增 HTTP 配置
20
+}
21
+
22
+// HTTPConfig HTTP客户端配置
23
+type HTTPConfig struct {
24
+	Timeout             int  `yaml:"timeout"`                 // 请求超时时间(秒)
25
+	MaxIdleConns        int  `yaml:"max_idle_conns"`          // 最大空闲连接数
26
+	MaxIdleConnsPerHost int  `yaml:"max_idle_conns_per_host"` // 每个主机的最大空闲连接数
27
+	IdleConnTimeout     int  `yaml:"idle_conn_timeout"`       // 空闲连接超时时间(秒)
28
+	MaxConnsPerHost     int  `yaml:"max_conns_per_host"`      // 每个主机的最大连接数
29
+	DisableCompression  bool `yaml:"disable_compression"`     // 是否禁用压缩
30
+	DisableKeepAlives   bool `yaml:"disable_keep_alives"`     // 是否禁用长连接
19
 }
31
 }
20
 
32
 
21
 // DBConfig 数据库配置
33
 // DBConfig 数据库配置
91
 	GetDoris() DorisConfig
103
 	GetDoris() DorisConfig
92
 	GetAuth() Auth
104
 	GetAuth() Auth
93
 	GetService() Service
105
 	GetService() Service
106
+	GetHTTP() HTTPConfig // 新增获取HTTP配置方法
94
 	IsDatabaseConfigured() bool
107
 	IsDatabaseConfigured() bool
95
 	IsRedisConfigured() bool
108
 	IsRedisConfigured() bool
96
 	IsDorisConfigured() bool
109
 	IsDorisConfigured() bool
110
+	IsHTTPConfigured() bool // 新增检查HTTP配置方法
97
 }
111
 }
98
 
112
 
99
 // 实现接口的具体类型
113
 // 实现接口的具体类型
121
 	return cw.config.Service
135
 	return cw.config.Service
122
 }
136
 }
123
 
137
 
138
+func (cw *configWrapper) GetHTTP() HTTPConfig {
139
+	return cw.config.HTTP
140
+}
141
+
124
 func (cw *configWrapper) IsDatabaseConfigured() bool {
142
 func (cw *configWrapper) IsDatabaseConfigured() bool {
125
 	db := cw.config.Database
143
 	db := cw.config.Database
126
 	return db.Type != "" &&
144
 	return db.Type != "" &&
141
 	return doris.FEHost != "" && doris.FEPort > 0
159
 	return doris.FEHost != "" && doris.FEPort > 0
142
 }
160
 }
143
 
161
 
162
+func (cw *configWrapper) IsHTTPConfigured() bool {
163
+	httpCfg := cw.config.HTTP
164
+	return httpCfg.Timeout > 0
165
+}
166
+
144
 func (cw *configWrapper) IsAuthConfigured() bool {
167
 func (cw *configWrapper) IsAuthConfigured() bool {
145
 	return cw.config.Auth.Token != ""
168
 	return cw.config.Auth.Token != ""
146
 }
169
 }
210
 			StreamLoadTimeout: 30,
233
 			StreamLoadTimeout: 30,
211
 			BatchSize:         1000,
234
 			BatchSize:         1000,
212
 		},
235
 		},
236
+		HTTP: HTTPConfig{
237
+			Timeout:             30,
238
+			MaxIdleConns:        100,
239
+			MaxIdleConnsPerHost: 10,
240
+			IdleConnTimeout:     90,
241
+			MaxConnsPerHost:     0, // 0表示不限制
242
+			DisableCompression:  false,
243
+			DisableKeepAlives:   false,
244
+		},
213
 	}
245
 	}
214
 	// 读取配置文件
246
 	// 读取配置文件
215
 	data, err := os.ReadFile(configFile)
247
 	data, err := os.ReadFile(configFile)

Ładowanie…
Anuluj
Zapisz