types(chore) document tag
This commit is contained in:
parent
0f48740eae
commit
daf2fd901a
10
types/tag.go
10
types/tag.go
|
@ -25,12 +25,16 @@ var (
|
|||
ErrTagInvalidCollor = errors.New("tag has invalid color")
|
||||
)
|
||||
|
||||
// A Tag is a simple structure used to categorize products.
|
||||
// Tag names are unique. Tag colors are base 10 RGB notation.
|
||||
type Tag struct {
|
||||
Id uint `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Color uint `json:"color"`
|
||||
}
|
||||
|
||||
// GenerateColor generates a random tag color using the tag's
|
||||
// name's SHA1.
|
||||
func (t *Tag) GenerateColor() error {
|
||||
if t.Name == "" {
|
||||
return ErrTagNameEmpty
|
||||
|
@ -45,6 +49,7 @@ func (t *Tag) GenerateColor() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// RGB converts the base 10 RGB color in an array of color values.
|
||||
func (t *Tag) RGB() ([]uint, error) {
|
||||
if !t.ValidColor() {
|
||||
return nil, ErrTagInvalidCollor
|
||||
|
@ -60,14 +65,19 @@ func (t *Tag) RGB() ([]uint, error) {
|
|||
return colors, nil
|
||||
}
|
||||
|
||||
// ValidColor verifies that the tag's color is valid.
|
||||
func (t *Tag) ValidColor() bool {
|
||||
return t.Color < colorRage
|
||||
}
|
||||
|
||||
// ValidName verifies that the tag has a name.
|
||||
// Uniqueness verification is the data source's job.
|
||||
func (t *Tag) ValidName() bool {
|
||||
return t.Name != ""
|
||||
}
|
||||
|
||||
// Valid verifies that the tag is valid.
|
||||
// A valid tag has a valid color and a name.
|
||||
func (t *Tag) Valid() bool {
|
||||
return t.ValidColor() && t.ValidName()
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue