improve configuration defaults handling

This commit is contained in:
Christoph Haas
2025-08-10 14:12:24 +02:00
parent 0037938f9e
commit 593bb983fb
3 changed files with 29 additions and 12 deletions

View File

@@ -44,6 +44,15 @@ type BackendBase struct {
DisplayName string `yaml:"display_name"` // A display name for the backend
}
// GetDisplayName returns the display name of the backend.
// If no display name is set, it falls back to the ID.
func (b BackendBase) GetDisplayName() string {
if b.DisplayName == "" {
return b.Id // Fallback to ID if no display name is set
}
return b.DisplayName
}
type BackendMikrotik struct {
BackendBase `yaml:",inline"` // Embed the base fields
@@ -71,3 +80,15 @@ func (b *BackendMikrotik) GetConcurrency() int {
}
return b.Concurrency
}
// GetApiTimeout returns the configured API timeout or a sane default (30 seconds)
// when the configured value is zero or negative.
func (b *BackendMikrotik) GetApiTimeout() time.Duration {
if b == nil {
return 30 * time.Second
}
if b.ApiTimeout <= 0 {
return 30 * time.Second
}
return b.ApiTimeout
}