1
0
Fork 0
mirror of https://github.com/kubernetes-sigs/node-feature-discovery.git synced 2024-12-14 11:57:51 +00:00

pkg/api/feature: revert back to structs instead of pointers

Less error prone, as no chance for a nil pointer dereference.
This commit is contained in:
Markus Lehtonen 2021-11-11 17:40:14 +02:00
parent 67330e1441
commit dd92c9a9ce
2 changed files with 12 additions and 12 deletions

View file

@ -20,28 +20,28 @@ package feature
// features to empty values
func NewDomainFeatures() *DomainFeatures {
return &DomainFeatures{
Keys: make(map[string]*KeyFeatureSet),
Values: make(map[string]*ValueFeatureSet),
Instances: make(map[string]*InstanceFeatureSet)}
Keys: make(map[string]KeyFeatureSet),
Values: make(map[string]ValueFeatureSet),
Instances: make(map[string]InstanceFeatureSet)}
}
func NewKeyFeatures(keys ...string) *KeyFeatureSet {
func NewKeyFeatures(keys ...string) KeyFeatureSet {
e := make(map[string]Nil, len(keys))
for _, k := range keys {
e[k] = Nil{}
}
return &KeyFeatureSet{Elements: e}
return KeyFeatureSet{Elements: e}
}
func NewValueFeatures(values map[string]string) *ValueFeatureSet {
func NewValueFeatures(values map[string]string) ValueFeatureSet {
if values == nil {
values = make(map[string]string)
}
return &ValueFeatureSet{Elements: values}
return ValueFeatureSet{Elements: values}
}
func NewInstanceFeatures(instances []InstanceFeature) *InstanceFeatureSet {
return &InstanceFeatureSet{Elements: instances}
func NewInstanceFeatures(instances []InstanceFeature) InstanceFeatureSet {
return InstanceFeatureSet{Elements: instances}
}
func NewInstanceFeature(attrs map[string]string) *InstanceFeature {

View file

@ -22,9 +22,9 @@ type Features map[string]*DomainFeatures
// DomainFeatures is the collection of all discovered features of one domain.
type DomainFeatures struct {
Keys map[string]*KeyFeatureSet `protobuf:"bytes,1,rep,name=keys"`
Values map[string]*ValueFeatureSet `protobuf:"bytes,2,rep,name=values"`
Instances map[string]*InstanceFeatureSet `protobuf:"bytes,3,rep,name=instances"`
Keys map[string]KeyFeatureSet `protobuf:"bytes,1,rep,name=keys"`
Values map[string]ValueFeatureSet `protobuf:"bytes,2,rep,name=values"`
Instances map[string]InstanceFeatureSet `protobuf:"bytes,3,rep,name=instances"`
}
// KeyFeatureSet is a set of simple features only containing names without values.