-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
265 additions
and
153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package deployment | ||
|
||
// LabelSet represents a set of labels on an address book entry. | ||
type LabelSet map[string]struct{} | ||
|
||
// NewLabelSet initializes a new LabelSet with any number of labels. | ||
func NewLabelSet(labels ...string) LabelSet { | ||
set := make(LabelSet) | ||
for _, lb := range labels { | ||
set[lb] = struct{}{} | ||
} | ||
return set | ||
} | ||
|
||
// Add inserts a labels into the set. | ||
func (ls LabelSet) Add(labels string) { | ||
ls[labels] = struct{}{} | ||
} | ||
|
||
// Remove deletes a labels from the set, if it exists. | ||
func (ls LabelSet) Remove(labels string) { | ||
delete(ls, labels) | ||
} | ||
|
||
// Contains checks if the set contains the given labels. | ||
func (ls LabelSet) Contains(labels string) bool { | ||
_, ok := ls[labels] | ||
return ok | ||
} | ||
|
||
// AsSlice returns the labels in a slice. Useful for printing or serialization. | ||
func (ls LabelSet) AsSlice() []string { | ||
out := make([]string, 0, len(ls)) | ||
for labels := range ls { | ||
out = append(out, labels) | ||
} | ||
return out | ||
} | ||
|
||
// Equal checks if two LabelSets are equal. | ||
func (ls LabelSet) Equal(other LabelSet) bool { | ||
if len(ls) != len(other) { | ||
return false | ||
} | ||
for label := range ls { | ||
if _, ok := other[label]; !ok { | ||
return false | ||
} | ||
} | ||
return true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.