add validation to RGBColor
This commit is contained in:
parent
f947b9b1ab
commit
d3c56d3aa8
4
color.go
4
color.go
@ -78,6 +78,10 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func NewRGBColor(r, g, b uint8) (*RGBColor, error) {
|
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
|
return &RGBColor{R: r, G: g, B: b}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user