Files
ss/internal/model/config.go
2026-07-19 20:01:38 +08:00

32 lines
990 B
Go

package model
// Config is the user-editable application configuration
// (ports to Python's Config(BaseModel) in models.py).
type Config struct {
AutoRefresh bool `yaml:"auto_refresh"`
RefreshIntervalHours int `yaml:"refresh_interval_hours"`
DefaultUserAgent string `yaml:"default_user_agent"`
TimeoutSeconds int `yaml:"timeout_seconds"`
}
// DefaultConfig mirrors the Pydantic field defaults.
func DefaultConfig() Config {
return Config{
AutoRefresh: false,
RefreshIntervalHours: 24,
DefaultUserAgent: "scientific-surfing/0.1.0",
TimeoutSeconds: 30,
}
}
// Validate mirrors the two @validator methods on Config in models.py.
func (c Config) Validate() error {
if c.RefreshIntervalHours < 1 {
return &ValidationError{Field: "refresh_interval_hours", Message: "must be at least 1 hour"}
}
if c.TimeoutSeconds < 1 {
return &ValidationError{Field: "timeout_seconds", Message: "must be at least 1 second"}
}
return nil
}