chore: use go generate to create Validate and Merge funcs on RoleConfigs
This commit is contained in:
parent
28b7993be4
commit
c9e93802eb
10 changed files with 236 additions and 200 deletions
|
|
@ -1,54 +1,12 @@
|
|||
package config
|
||||
|
||||
import "errors"
|
||||
|
||||
//go:generate -command roleconfig go run git.wzray.com/homelab/hivemind/internal/codegen/roleconfig
|
||||
//go:generate roleconfig -name MasterConfig
|
||||
type MasterConfig struct {
|
||||
ObserverInterval int `toml:"observer_interval"`
|
||||
BackoffSeconds int `toml:"backoff_seconds"`
|
||||
BackoffCount int `toml:"backoff_count"`
|
||||
NodeTimeout int `toml:"node_timeout"`
|
||||
ObserverInterval int `toml:"observer_interval" gen:"positive"`
|
||||
BackoffSeconds int `toml:"backoff_seconds" gen:"positive"`
|
||||
BackoffCount int `toml:"backoff_count" gen:"positive"`
|
||||
NodeTimeout int `toml:"node_timeout" gen:"positive"`
|
||||
|
||||
baseRoleConfig
|
||||
}
|
||||
|
||||
func (c MasterConfig) Validate() error {
|
||||
if c.ObserverInterval < 1 {
|
||||
return errors.New("invalid observer_interval")
|
||||
}
|
||||
|
||||
if c.BackoffSeconds < 1 {
|
||||
return errors.New("invalid backoff_seconds")
|
||||
}
|
||||
|
||||
if c.BackoffCount < 1 {
|
||||
return errors.New("invalid backoff_count")
|
||||
}
|
||||
|
||||
if c.NodeTimeout < 1 {
|
||||
return errors.New("invalid node_timeout")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *MasterConfig) Merge(other MasterConfig) {
|
||||
if other.set {
|
||||
c.set = true
|
||||
}
|
||||
|
||||
if other.ObserverInterval != 0 {
|
||||
c.ObserverInterval = other.ObserverInterval
|
||||
}
|
||||
|
||||
if other.BackoffSeconds != 0 {
|
||||
c.BackoffSeconds = other.BackoffSeconds
|
||||
}
|
||||
|
||||
if other.BackoffCount != 0 {
|
||||
c.BackoffCount = other.BackoffCount
|
||||
}
|
||||
|
||||
if other.NodeTimeout != 0 {
|
||||
c.NodeTimeout = other.NodeTimeout
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue