feat: migrate to golang
This commit is contained in:
31
internal/model/config.go
Normal file
31
internal/model/config.go
Normal file
@ -0,0 +1,31 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user