mirror of
https://github.com/kaaninchen/Laterna.git
synced 2026-09-17 19:12:48 +00:00
🐛 fix(utils.go): check if hex-code starts with an #
This commit is contained in:
@@ -104,7 +104,7 @@ func ViewColor(id int) (*models.LampState, error) {
|
||||
|
||||
func SetColor(id int, color string) error {
|
||||
if !utils.IsValidHexColor(color) {
|
||||
return errors.New("invalid HEX Code: %s")
|
||||
return errors.New("invalid HEX Code")
|
||||
}
|
||||
currentColor, err := ViewColor(id)
|
||||
if err != nil {
|
||||
|
||||
+1
-1
@@ -26,7 +26,7 @@ func IDtoInt(id string) (int, error) {
|
||||
}
|
||||
|
||||
func IsValidHexColor(color string) bool {
|
||||
pattern := `^#?([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$`
|
||||
pattern := `^#(?:[A-Fa-f0-9]{3}|[A-Fa-f0-9]{6})$`
|
||||
match, _ := regexp.MatchString(pattern, color)
|
||||
return match
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user