This commit is contained in:
lpf
2026-02-15 20:40:06 +08:00
parent 2caff904be
commit 05821ff2fd
6 changed files with 655 additions and 37 deletions

View File

@@ -15,6 +15,7 @@ type Config struct {
Channels ChannelsConfig `json:"channels"`
Providers ProvidersConfig `json:"providers"`
Gateway GatewayConfig `json:"gateway"`
Cron CronConfig `json:"cron"`
Tools ToolsConfig `json:"tools"`
Logging LoggingConfig `json:"logging"`
Sentinel SentinelConfig `json:"sentinel"`
@@ -118,6 +119,15 @@ type GatewayConfig struct {
Port int `json:"port" env:"CLAWGO_GATEWAY_PORT"`
}
type CronConfig struct {
MinSleepSec int `json:"min_sleep_sec" env:"CLAWGO_CRON_MIN_SLEEP_SEC"`
MaxSleepSec int `json:"max_sleep_sec" env:"CLAWGO_CRON_MAX_SLEEP_SEC"`
RetryBackoffBaseSec int `json:"retry_backoff_base_sec" env:"CLAWGO_CRON_RETRY_BACKOFF_BASE_SEC"`
RetryBackoffMaxSec int `json:"retry_backoff_max_sec" env:"CLAWGO_CRON_RETRY_BACKOFF_MAX_SEC"`
MaxConsecutiveFailureRetries int `json:"max_consecutive_failure_retries" env:"CLAWGO_CRON_MAX_CONSECUTIVE_FAILURE_RETRIES"`
MaxWorkers int `json:"max_workers" env:"CLAWGO_CRON_MAX_WORKERS"`
}
type WebSearchConfig struct {
APIKey string `json:"api_key" env:"CLAWGO_TOOLS_WEB_SEARCH_API_KEY"`
MaxResults int `json:"max_results" env:"CLAWGO_TOOLS_WEB_SEARCH_MAX_RESULTS"`
@@ -285,6 +295,14 @@ func DefaultConfig() *Config {
Host: "0.0.0.0",
Port: 18790,
},
Cron: CronConfig{
MinSleepSec: 1,
MaxSleepSec: 30,
RetryBackoffBaseSec: 30,
RetryBackoffMaxSec: 1800,
MaxConsecutiveFailureRetries: 5,
MaxWorkers: 4,
},
Tools: ToolsConfig{
Web: WebToolsConfig{
Search: WebSearchConfig{

View File

@@ -46,6 +46,30 @@ func Validate(cfg *Config) []error {
if cfg.Gateway.Port <= 0 || cfg.Gateway.Port > 65535 {
errs = append(errs, fmt.Errorf("gateway.port must be in 1..65535"))
}
if cfg.Cron.MinSleepSec <= 0 {
errs = append(errs, fmt.Errorf("cron.min_sleep_sec must be > 0"))
}
if cfg.Cron.MaxSleepSec <= 0 {
errs = append(errs, fmt.Errorf("cron.max_sleep_sec must be > 0"))
}
if cfg.Cron.MinSleepSec > cfg.Cron.MaxSleepSec {
errs = append(errs, fmt.Errorf("cron.min_sleep_sec must be <= cron.max_sleep_sec"))
}
if cfg.Cron.RetryBackoffBaseSec <= 0 {
errs = append(errs, fmt.Errorf("cron.retry_backoff_base_sec must be > 0"))
}
if cfg.Cron.RetryBackoffMaxSec <= 0 {
errs = append(errs, fmt.Errorf("cron.retry_backoff_max_sec must be > 0"))
}
if cfg.Cron.RetryBackoffBaseSec > cfg.Cron.RetryBackoffMaxSec {
errs = append(errs, fmt.Errorf("cron.retry_backoff_base_sec must be <= cron.retry_backoff_max_sec"))
}
if cfg.Cron.MaxConsecutiveFailureRetries < 0 {
errs = append(errs, fmt.Errorf("cron.max_consecutive_failure_retries must be >= 0"))
}
if cfg.Cron.MaxWorkers <= 0 {
errs = append(errs, fmt.Errorf("cron.max_workers must be > 0"))
}
if cfg.Logging.Enabled {
if cfg.Logging.Dir == "" {