mirror of
https://github.com/k3s-io/k3s.git
synced 2024-06-07 19:41:36 +00:00
60 lines
1.1 KiB
Go
60 lines
1.1 KiB
Go
|
package data
|
||
|
|
||
|
import (
|
||
|
"github.com/rancher/wrangler/pkg/data/convert"
|
||
|
)
|
||
|
|
||
|
type List []map[string]interface{}
|
||
|
|
||
|
type Object map[string]interface{}
|
||
|
|
||
|
func New() Object {
|
||
|
return map[string]interface{}{}
|
||
|
}
|
||
|
|
||
|
func (o Object) Map(names ...string) Object {
|
||
|
v := GetValueN(o, names...)
|
||
|
m := convert.ToMapInterface(v)
|
||
|
return m
|
||
|
}
|
||
|
|
||
|
func (o Object) Slice(names ...string) (result []Object) {
|
||
|
v := GetValueN(o, names...)
|
||
|
for _, item := range convert.ToInterfaceSlice(v) {
|
||
|
result = append(result, convert.ToMapInterface(item))
|
||
|
}
|
||
|
return
|
||
|
}
|
||
|
|
||
|
func (o Object) Values() (result []Object) {
|
||
|
for k := range o {
|
||
|
result = append(result, o.Map(k))
|
||
|
}
|
||
|
return
|
||
|
}
|
||
|
|
||
|
func (o Object) String(names ...string) string {
|
||
|
v := GetValueN(o, names...)
|
||
|
return convert.ToString(v)
|
||
|
}
|
||
|
|
||
|
func (o Object) StringSlice(names ...string) []string {
|
||
|
v := GetValueN(o, names...)
|
||
|
return convert.ToStringSlice(v)
|
||
|
}
|
||
|
|
||
|
func (o Object) Set(key string, obj interface{}) {
|
||
|
if o == nil {
|
||
|
return
|
||
|
}
|
||
|
o[key] = obj
|
||
|
}
|
||
|
|
||
|
func (o Object) SetNested(obj interface{}, key ...string) {
|
||
|
PutValue(o, obj, key...)
|
||
|
}
|
||
|
|
||
|
func (o Object) Bool(key ...string) bool {
|
||
|
return convert.ToBool(GetValueN(o, key...))
|
||
|
}
|