Validate colors from configuration file
This commit is contained in:
parent
1ac9487c76
commit
b1894b38de
@ -100,5 +100,31 @@ func (c *Config) Validate() error {
|
|||||||
if c.AccessToken == "" {
|
if c.AccessToken == "" {
|
||||||
err = errors.New("access_token is not set")
|
err = errors.New("access_token is not set")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err = c.validateColors(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Config) validateColors() (err error) {
|
||||||
|
if len(c.Colors) > 0 {
|
||||||
|
for name, hsb := range c.Colors {
|
||||||
|
if len(hsb) != 3 {
|
||||||
|
return fmt.Errorf("color '%s' needs three values", name)
|
||||||
|
}
|
||||||
|
h, s, b := hsb[0], hsb[1], hsb[2]
|
||||||
|
if h < 0 || h > 360 {
|
||||||
|
return fmt.Errorf("color '%s' hue value must be between 0.0-360.0", name)
|
||||||
|
}
|
||||||
|
if s < 0 || b > 1 {
|
||||||
|
return fmt.Errorf("color '%s' saturation value must be between 0.0-1.0", name)
|
||||||
|
}
|
||||||
|
if b < 0 || b > 1 {
|
||||||
|
return fmt.Errorf("color '%s' brightness value must be between 0.0-1.0", name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user