feat(botfilter): config.go part 2/4

This commit is contained in:
hoelee committed 2026-03-12 10:05:00 +08:00
1 parent e1104c3c33
commit f22c5733a5
1 file changed
+16
+16
View File
@@ -88,3 +88,19 @@ func compileConfig(input *Config) (*compiledConfig, error) {
cfg.BlockedExtensions = append([]string(nil), input.BlockedExtensions...)
cfg.RandomArticlePatterns = append([]string(nil), input.RandomArticlePatterns...)
defaults := CreateConfig()
applyDefaults(&cfg, defaults)
if cfg.StatusCode < 400 || cfg.StatusCode > 599 {
return nil, fmt.Errorf("botfilter: statusCode must be between 400 and 599")
}
if cfg.TemporaryBanMinutes <= 0 {
return nil, fmt.Errorf("botfilter: temporaryBanMinutes must be greater than zero")
}
if cfg.ScoreThreshold <= 0 || cfg.ScoreWindowMinutes <= 0 {
return nil, fmt.Errorf("botfilter: scoreThreshold and scoreWindowMinutes must be greater than zero")
}
if cfg.MaxTrackedIPs <= 0 || cfg.MaxScoreEventsPerIP <= 0 {
return nil, fmt.Errorf("botfilter: maxTrackedIPs and maxScoreEventsPerIP must be greater than zero")
}