package ultraviolet import ( "strconv" "strings" ) type Color struct { Red int Green int Blue int Alpha int } func ColorFromHex(value string) Color { if len(value) != 8 { return Color{} } if !strings.HasPrefix(value, "0x") { return Color{} } red, err := strconv.ParseInt(value[2:4], 16, 16) if err != nil { return Color{} } green, err := strconv.ParseInt(value[4:6], 16, 16) if err != nil { return Color{} } blue, err := strconv.ParseInt(value[6:8], 16, 16) if err != nil { return Color{} } return Color{ Red: int(red), Green: int(green), Blue: int(blue), Alpha: 255, } }