MCPcopy Create free account
hub / github.com/V2RaySSR/RealityChecker / validateAndSetDefaults

Function validateAndSetDefaults

internal/config/config.go:169–220  ·  view source on GitHub ↗

validateAndSetDefaults 验证配置并设置默认值

(config *types.Config)

Source from the content-addressed store, hash-verified

167
168// validateAndSetDefaults 验证配置并设置默认值
169func validateAndSetDefaults(config *types.Config) {
170 // 网络配置验证
171 if config.Network.Timeout <= 0 {
172 config.Network.Timeout = 30 * time.Second
173 }
174 if config.Network.Retries < 0 {
175 config.Network.Retries = 3
176 }
177 if len(config.Network.DNSServers) == 0 {
178 config.Network.DNSServers = []string{"8.8.8.8", "1.1.1.1"}
179 }
180
181 // TLS配置验证
182 if config.TLS.MinVersion == 0 {
183 config.TLS.MinVersion = 771 // TLS 1.2
184 }
185 if config.TLS.MaxVersion == 0 {
186 config.TLS.MaxVersion = 772 // TLS 1.3
187 }
188
189 // 并发配置验证
190 if config.Concurrency.MaxConcurrent <= 0 {
191 config.Concurrency.MaxConcurrent = 8
192 }
193 if config.Concurrency.CheckTimeout <= 0 {
194 config.Concurrency.CheckTimeout = 30 * time.Second
195 }
196 if config.Concurrency.CacheTTL <= 0 {
197 config.Concurrency.CacheTTL = 5 * time.Minute
198 }
199
200 // 输出配置验证
201 if config.Output.Format == "" {
202 config.Output.Format = "table"
203 }
204
205 // 缓存配置验证
206 if config.Cache.TTL <= 0 {
207 config.Cache.TTL = 5 * time.Minute
208 }
209 if config.Cache.MaxSize <= 0 {
210 config.Cache.MaxSize = 1000
211 }
212
213 // 批量配置验证
214 if config.Batch.ReportFormat == "" {
215 config.Batch.ReportFormat = "text"
216 }
217 if config.Batch.Timeout <= 0 {
218 config.Batch.Timeout = 60 * time.Second
219 }
220}

Callers 1

LoadConfigFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected