Documentation ¶
Index ¶
- func Must[T MustConstraint](t T, err error) T
- type LessFunc
- type MatchFunc
- type MustConstraint
- type Tag
- func (t Tag) HasFunc(fn MatchFunc) bool
- func (t Tag) HasName(name string) bool
- func (t Tag) HasValues(values ...string) bool
- func (t Tag) IsLabel() bool
- func (t Tag) IsMultiValue() bool
- func (t Tag) IsSingleValue() bool
- func (t Tag) Name() string
- func (t Tag) String() string
- func (t Tag) Value() string
- func (t Tag) Values() []string
- type TagGroup
- func (g *TagGroup) Add(tags ...Tag)
- func (g *TagGroup) Contains(tags ...Tag) bool
- func (g *TagGroup) ContainsFunc(fn MatchFunc) bool
- func (g *TagGroup) ContainsNames(names ...string) bool
- func (g *TagGroup) ContainsValues(values ...string) bool
- func (g *TagGroup) FindFunc(fn MatchFunc) (found []Tag)
- func (g *TagGroup) FindNames(names ...string) []Tag
- func (g *TagGroup) FindValues(values ...string) []Tag
- func (g *TagGroup) Name() string
- func (g *TagGroup) Remove(tags ...Tag)
- func (g *TagGroup) RemoveFunc(fn MatchFunc)
- func (g *TagGroup) RemoveNames(names ...string)
- func (g *TagGroup) RemoveValues(values ...string)
- func (g *TagGroup) Rename(newName string) error
- func (g *TagGroup) SortFunc(fn LessFunc)
- func (g *TagGroup) SortNames(desc bool)
- func (g *TagGroup) Tags() []Tag
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type MustConstraint ¶
MustConstraint is a type constraint for the Must function.
type Tag ¶
type Tag struct {
// contains filtered or unexported fields
}
Tag can be a label (a tag without a value), a single value tag (a tag with a name and one value) or a multiple value tag (a tag with a name and more than one value).
func New ¶
New creates a tag with the name and values.
The name cannot be an empty string. Empty-string values will be removed. Repeating values will be removed, i.e. values will be made unique.
You can also use the convenience functions to create tags: NewLabel, NewSingleValue or NewMultiValue.
func NewLabel ¶
NewLabel creates a label tag (a tag without a value).
The name cannot be an empty string.
func NewMultiValue ¶
NewMultiValue creates a multiple value tag (a tag with more than one value).
The name and values cannot be empty strings. Repeating values will be removed, i.e. values will be made unique. At least two unique values are required.
func NewSingleValue ¶
NewSingleValue creates a single value tag (a tag with one value).
The name and value cannot be empty strings.
func Parse ¶
Parse tries to parse a string representation of a tag and returns the corresponding Tag or an error.
The string must be in the name[:value,...] format.
Examples:
Must(Parse("label")) -> Tag{name: "label", values: nil} Must(Parse("single:value")) -> Tag{name: "single", values: []string{"value"}} Must(Parse("multi:value1,value2")) -> Tag{name: "multi", values: []string{"value1", "value2"}}
This function is the reverse of the Tag.String method.
func (Tag) IsMultiValue ¶
IsMultiValue returns true if the tag is a multiple value tag.
func (Tag) IsSingleValue ¶
IsSingleValue returns true if the tag is a single value tag.
func (Tag) String ¶
String returns a string representation of the tag in the name[:value,...] format.
Examples:
Must(NewLabel("label")).String() -> "label" Must(NewSingleValue("single", "value").String() -> "single:value" Must(NewMultiValue("multi", "value1", "value2").String() -> "multi:value1,value2"
This method is the reverse of the Parse function.
func (Tag) Value ¶
Value returns the tag value.
If the tag has no values (it's a label) it returns an empty string.
If the tag has multiple values (it's a multiple value tag) it returns just the first value. To get all values use the Tag.Values method.
type TagGroup ¶
type TagGroup struct {
// contains filtered or unexported fields
}
TagGroup is a group of related tags.
func NewGroup ¶
NewGroup creates a group with the specified name and adds the provided tags to it.
The group name cannot be an empty string. The tag names must be unique, see the TagGroup.Add method docs.
func NewGroupWithGeneratedName ¶
NewGroupWithGeneratedName creates a group with a generated name and adds the specified tags to it.
The tag names must be unique, see the TagGroup.Add method docs.
func (*TagGroup) Add ¶
Add adds tags to the group.
If there are multiple tags with the same Tag.Name, only the last one will be added, i.e. the tag names must be unique.
func (*TagGroup) Contains ¶
Contains returns true if the group contains the tags. The tags must match by both name and values.
func (*TagGroup) ContainsFunc ¶
ContainsFunc returns true if the group contains tags matching the fn. The tags must match by both name and values.
func (*TagGroup) ContainsNames ¶
ContainsNames returns true if the group contains tags matching the names.
func (*TagGroup) ContainsValues ¶
ContainsValues returns true if the group contains tags matching all the values, i.e. only tags that have all the values are considered matches.
func (*TagGroup) FindValues ¶
FindValues returns tags matching all the values, i.e. only tags that have all the values are considered matches.
func (*TagGroup) Remove ¶
Remove removes the matching tags from the group. The tags must match by both name and values.
func (*TagGroup) RemoveFunc ¶
RemoveFunc removes tags matching the fn from the group.
func (*TagGroup) RemoveNames ¶
RemoveNames removes tags matching the names from the group.
func (*TagGroup) RemoveValues ¶
RemoveValues removes tags matching all the values from the group, i.e. only tags that have all the values are considered matches.
func (*TagGroup) SortNames ¶
SortNames sorts the tags by their name in ascending (desc == false) or descending (desc == true) order.
func (*TagGroup) Tags ¶
Tags returns the group tags.
Tags can be added to the group with the TagGroup.Add method.