1
0
Fork 0
mirror of https://github.com/kubernetes-sigs/node-feature-discovery.git synced 2025-03-05 08:17:04 +00:00

pkg/utils: add UnmarshalJSON method to StringSetVal

Make it possible to specify values in yaml as an array like

  conf:
    - foo
    - bar

Instead of unwieldy map like

  conf:
    foo:
    bar:
This commit is contained in:
Markus Lehtonen 2023-03-14 10:53:24 +02:00
parent adea670ded
commit 4a8fc811be

View file

@ -84,6 +84,18 @@ func (a *StringSetVal) String() string {
return strings.Join(vals, ",")
}
// UnmarshalJSON implements the Unmarshaler interface from "encoding/json"
func (a *StringSetVal) UnmarshalJSON(data []byte) error {
var tmp []string
if err := json.Unmarshal(data, &tmp); err != nil {
return err
}
for _, v := range tmp {
(*a)[v] = struct{}{}
}
return nil
}
// StringSliceVal is a Value encapsulating a slice of comma-separated strings
type StringSliceVal []string