{"modulePath":"github.com/UnityTech/client-go","version":"v2.0.0+incompatible","isLatest":false,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package labels\n\nPackage labels implements a simple label system, parsing and matching selectors with sets of labels.\n\n## Functions\n\n```go\nfunc AreLabelsInWhiteList(labels, whitelist Set) bool\n```\nAreLabelsInWhiteList verifies if the provided label list is in the provided whitelist and returns true, otherwise false.\n\n```go\nfunc Conflicts(labels1, labels2 Set) bool\n```\nConflicts takes 2 maps and returns true if there a key match between the maps but the value doesn't match, and returns false in other cases\n\n```go\nfunc Equals(labels1, labels2 Set) bool\n```\nEquals returns true if the given maps are equal\n\n```go\nfunc FormatLabels(labelMap map[string]string) string\n```\nFormatLables convert label map into plain string\n\n## Types\n\n```go\ntype ByKey []Requirement\n```\nSort by key to obtain determisitic parser\n\n```go\nfunc (a ByKey) Len() int\n```\n\n```go\nfunc (a ByKey) Less(i, j int) bool\n```\n\n```go\nfunc (a ByKey) Swap(i, j int)\n```\n\n```go\ntype Labels interface {\n\t// Has returns whether the provided label exists.\n\tHas(label string) (exists bool)\n\n\t// Get returns the value for the provided label.\n\tGet(label string) (value string)\n}\n```\nLabels allows you to present labels independently from their storage.\n\n```go\ntype Lexer struct {\n\t// contains filtered or unexported fields\n}\n```\nLexer represents the Lexer struct for label selector. It contains necessary informationt to tokenize the input string\n\n```go\nfunc (l *Lexer) Lex() (tok Token, lit string)\n```\nLex returns a pair of Token and the literal literal is meaningfull only for IdentifierToken token\n\n```go\ntype Parser struct {\n\t// contains filtered or unexported fields\n}\n```\nParser data structure contains the label selector parser data structure\n\n```go\ntype ParserContext int\n```\nParser context represents context during parsing: some literal for example 'in' and 'notin' can be recognized as operator for example 'x in (a)' but it can be recognized as value for example 'value in (in)'\n\n```go\nconst (\n\tKeyAndOperator ParserContext = iota\n\tValues\n)\n```\n\n```go\ntype Requirement struct {\n\t// contains filtered or unexported fields\n}\n```\nRequirement contains values, a key, and an operator that relates the key and values. The zero value of Requirement is invalid. Requirement implements both set based match and exact match Requirement should be initialized via NewRequirement constructor for creating a valid Requirement.\n\n```go\nfunc NewRequirement(key string, op selection.Operator, vals []string) (*Requirement, error)\n```\nNewRequirement is the constructor for a Requirement. If any of these rules is violated, an error is returned: (1) The operator can only be In, NotIn, Equals, DoubleEquals, NotEquals, Exists, or DoesNotExist. (2) If the operator is In or NotIn, the values set must be non-empty. (3) If the operator is Equals, DoubleEquals, or NotEquals, the values set must contain one value. (4) If the operator is Exists or DoesNotExist, the value set must be empty. (5) If the operator is Gt or Lt, the values set must contain only one value, which will be interpreted as an integer. (6) The key is invalid due to its length, or sequence\n\n\tof characters. See validateLabelKey for more details.\n\nThe empty string is a valid value in the input values set.\n\n```go\nfunc ParseToRequirements(selector string) ([]Requirement, error)\n```\nParseToRequirements takes a string representing a selector and returns a list of requirements. This function is suitable for those callers that perform additional processing on selector requirements. See the documentation for Parse() function for more details. TODO: Consider exporting the internalSelector type instead.\n\n```go\nfunc (r *Requirement) Key() string\n```\n\n```go\nfunc (r *Requirement) Matches(ls Labels) bool\n```\nMatches returns true if the Requirement matches the input Labels. There is a match in the following cases: (1) The operator is Exists and Labels has the Requirement's key. (2) The operator is In, Labels has the Requirement's key and Labels'\n\n\tvalue for that key is in Requirement's value set.\n\n(3) The operator is NotIn, Labels has the Requirement's key and\n\n\tLabels' value for that key is not in Requirement's value set.\n\n(4) The operator is DoesNotExist or NotIn and Labels does not have the\n\n\tRequirement's key.\n\n(5) The operator is GreaterThanOperator or LessThanOperator, and Labels has\n\n\tthe Requirement's key and the corresponding value satisfies mathematical inequality.\n\n```go\nfunc (r *Requirement) Operator() selection.Operator\n```\n\n```go\nfunc (r *Requirement) String() string\n```\nString returns a human-readable string that represents this Requirement. If called on an invalid Requirement, an error is returned. See NewRequirement for creating a valid Requirement.\n\n```go\nfunc (r *Requirement) Values() sets.String\n```\n\n```go\ntype Requirements []Requirement\n```\nRequirements is AND of all requirements.\n\n```go\ntype ScannedItem struct {\n\t// contains filtered or unexported fields\n}\n```\nThe item produced by the lexer. It contains the Token and the literal.\n\n```go\ntype Selector interface {\n\t// Matches returns true if this selector matches the given set of labels.\n\tMatches(Labels) bool\n\n\t// Empty returns true if this selector does not restrict the selection space.\n\tEmpty() bool\n\n\t// String returns a human readable string that represents this selector.\n\tString() string\n\n\t// Add adds requirements to the Selector\n\tAdd(r ...Requirement) Selector\n\n\t// Requirements converts this interface into Requirements to expose\n\t// more detailed selection information.\n\t// If there are querying parameters, it will return converted requirements and selectable=true.\n\t// If this selector doesn't want to select anything, it will return selectable=false.\n\tRequirements() (requirements Requirements, selectable bool)\n}\n```\nSelector represents a label selector.\n\n```go\nfunc Everything() Selector\n```\nEverything returns a selector that matches all labels.\n\n```go\nfunc NewSelector() Selector\n```\n\n```go\nfunc Nothing() Selector\n```\nNothing returns a selector that matches no labels\n\n```go\nfunc Parse(selector string) (Selector, error)\n```\nParse takes a string representing a selector and returns a selector object, or an error. This parsing function differs from ParseSelector as they parse different selectors with different syntaxes. The input will cause an error if it does not follow this form:\n\n\\\u003cselector-syntax\u003e ::= \\\u003crequirement\u003e | \\\u003crequirement\u003e \",\" \\\u003cselector-syntax\u003e ] \\\u003crequirement\u003e ::= \\[!] KEY \\[ \\\u003cset-based-restriction\u003e | \\\u003cexact-match-restriction\u003e ] \\\u003cset-based-restriction\u003e ::= \"\" | \\\u003cinclusion-exclusion\u003e \\\u003cvalue-set\u003e \\\u003cinclusion-exclusion\u003e ::= \\\u003cinclusion\u003e | \\\u003cexclusion\u003e\n\n\t\u003cexclusion\u003e ::= \"notin\"\n\t\u003cinclusion\u003e ::= \"in\"\n\t\u003cvalue-set\u003e ::= \"(\" \u003cvalues\u003e \")\"\n\t   \u003cvalues\u003e ::= VALUE | VALUE \",\" \u003cvalues\u003e\n\n\\\u003cexact-match-restriction\u003e ::= \\[\"=\"|\"==\"|\"!=\"] VALUE KEY is a sequence of one or more characters following \\[ DNS\\_SUBDOMAIN \"/\" ] DNS\\_LABEL. Max length is 63 characters. VALUE is a sequence of zero or more characters \"(\\[A-Za-z0-9\\_-\\\\.])\". Max length is 63 characters. Delimiter is white space: (' ', '\\\\t') Example of valid syntax:\n\n\t\"x in (foo,,baz),y,z notin ()\"\n\nNote:\n\n\t(1) Inclusion - \" in \" - denotes that the KEY exists and is equal to any of the\n\t    VALUEs in its requirement\n\t(2) Exclusion - \" notin \" - denotes that the KEY is not equal to any\n\t    of the VALUEs in its requirement or does not exist\n\t(3) The empty string is a valid VALUE\n\t(4) A requirement with just a KEY - as in \"y\" above - denotes that\n\t    the KEY exists and can be any VALUE.\n\t(5) A requirement with just !KEY requires that the KEY not exist.\n\n```go\nfunc SelectorFromSet(ls Set) Selector\n```\nSelectorFromSet returns a Selector which will match exactly the given Set. A nil and empty Sets are considered equivalent to Everything().\n\n```go\nfunc SelectorFromValidatedSet(ls Set) Selector\n```\nSelectorFromValidatedSet returns a Selector which will match exactly the given Set. A nil and empty Sets are considered equivalent to Everything(). It assumes that Set is already validated and doesn't do any validation.\n\n```go\ntype Set map[string]string\n```\nSet is a map of label:value. It implements Labels.\n\n```go\nfunc ConvertSelectorToLabelsMap(selector string) (Set, error)\n```\nConvertSelectorToLabelsMap converts selector string to labels map and validates keys and values\n\n```go\nfunc Merge(labels1, labels2 Set) Set\n```\nMerge combines given maps, and does not check for any conflicts between the maps. In case of conflicts, second map (labels2) wins\n\n```go\nfunc (ls Set) AsSelector() Selector\n```\nAsSelector converts labels into a selectors.\n\n```go\nfunc (ls Set) AsSelectorPreValidated() Selector\n```\nAsSelectorPreValidated converts labels into a selector, but assumes that labels are already validated and thus don't preform any validation. According to our measurements this is significantly faster in codepaths that matter at high sccale.\n\n```go\nfunc (ls Set) Get(label string) string\n```\nGet returns the value in the map for the provided label.\n\n```go\nfunc (ls Set) Has(label string) bool\n```\nHas returns whether the provided label exists in the map.\n\n```go\nfunc (ls Set) String() string\n```\nString returns all labels listed as a human readable string. Conveniently, exactly the format that ParseSelector takes.\n\n```go\ntype Token int\n```\nconstants definition for lexer token\n\n```go\nconst (\n\tErrorToken Token = iota\n\tEndOfStringToken\n\tClosedParToken\n\tCommaToken\n\tDoesNotExistToken\n\tDoubleEqualsToken\n\tEqualsToken\n\tGreaterThanToken\n\tIdentifierToken // to represent keys and values\n\tInToken\n\tLessThanToken\n\tNotEqualsToken\n\tNotInToken\n\tOpenParToken\n)\n```\n\n","path":"github.com/UnityTech/client-go/pkg/labels","name":"labels","synopsis":"Package labels implements a simple label system, parsing and matching selectors with sets of labels.","isRedistributable":true}
