add validation to RGBColor

This commit is contained in:
Ryan Cavicchioni 2020-03-24 00:26:06 -05:00
parent f947b9b1ab
commit d3c56d3aa8
Signed by: ryanc
GPG Key ID: 877EEDAF9245103D

View File

@ -78,6 +78,10 @@ var (
)
func NewRGBColor(r, g, b uint8) (*RGBColor, error) {
if (r < 0 || r > 255) && (g < 0 || r > 255) && (b < 0 || b > 255) {
return nil, errors.New("values must be between 0-255")
}
return &RGBColor{R: r, G: g, B: b}, nil
}