change err check flow
This commit is contained in:
parent
909eeb00af
commit
01e9a44fdf
1 changed files with 5 additions and 6 deletions
|
|
@ -512,19 +512,18 @@ var NamedColors = []string{
|
||||||
var ColorHexRegex = regexp.MustCompile(`^#(([0-9a-fA-F]{2}){3}|([0-9a-fA-F]){3})$`)
|
var ColorHexRegex = regexp.MustCompile(`^#(([0-9a-fA-F]{2}){3}|([0-9a-fA-F]){3})$`)
|
||||||
|
|
||||||
func ValidColor(color string) bool {
|
func ValidColor(color string) bool {
|
||||||
|
|
||||||
if IsGradient(color) {
|
if IsGradient(color) {
|
||||||
gradient, err := ParseGradient(color)
|
gradient, err := ParseGradient(color)
|
||||||
|
if err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
for _, colorStop := range gradient.ColorStops {
|
for _, colorStop := range gradient.ColorStops {
|
||||||
_, err = csscolorparser.Parse(colorStop.Color)
|
_, err = csscolorparser.Parse(colorStop.Color)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
break
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return err == nil
|
} else if !go2.Contains(NamedColors, strings.ToLower(color)) && !ColorHexRegex.MatchString(color) {
|
||||||
}
|
|
||||||
|
|
||||||
if !go2.Contains(NamedColors, strings.ToLower(color)) && !ColorHexRegex.MatchString(color) {
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue