mirror of
https://github.com/kubernetes-sigs/node-feature-discovery.git
synced 2025-03-05 16:27:05 +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:
parent
adea670ded
commit
4a8fc811be
1 changed files with 12 additions and 0 deletions
|
@ -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
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue