/
label_selector.go
54 lines (44 loc) · 1.25 KB
/
label_selector.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*
Copyright (c) 2019 VMware, Inc. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package component
import "encoding/json"
// LabelSelectorConfig is the contents of LabelSelector
type LabelSelectorConfig struct {
Key string `json:"key"`
Value string `json:"value"`
}
// LabelSelector is a component for a single label within a selector
type LabelSelector struct {
base
Config LabelSelectorConfig `json:"config"`
}
// NewLabelSelector creates a labelSelector component
func NewLabelSelector(k, v string) *LabelSelector {
return &LabelSelector{
base: newBase(typeLabelSelector, nil),
Config: LabelSelectorConfig{
Key: k,
Value: v,
},
}
}
// Name is the name of the LabelSelector.
func (t *LabelSelector) Name() string {
return t.Config.Key
}
// GetMetadata accesses the components metadata. Implements Component.
func (t *LabelSelector) GetMetadata() Metadata {
return t.Metadata
}
// IsSelector marks the component as selector flavor. Implements Selector.
func (t *LabelSelector) IsSelector() {
}
type labelSelectorMarshal LabelSelector
// MarshalJSON implements json.Marshaler
func (t *LabelSelector) MarshalJSON() ([]byte, error) {
m := labelSelectorMarshal(*t)
m.Metadata.Type = typeLabelSelector
return json.Marshal(&m)
}