1
0
mirror of https://github.com/rancher/types.git synced 2025-08-31 21:00:16 +00:00
Files
types/mapper/resource.go

53 lines
1.0 KiB
Go
Raw Normal View History

2017-11-11 21:14:05 -07:00
package mapper
import (
"strings"
"github.com/rancher/norman/types"
2017-11-29 14:38:39 -07:00
"github.com/rancher/norman/types/values"
2017-11-11 21:14:05 -07:00
)
2017-11-14 21:45:08 -07:00
type PivotMapper struct {
Plural bool
2017-11-11 21:14:05 -07:00
}
2017-11-14 21:45:08 -07:00
func (r PivotMapper) FromInternal(data map[string]interface{}) {
2017-11-11 21:14:05 -07:00
for key, value := range data {
mapValue, ok := value.(map[string]interface{})
if !ok {
continue
}
for subKey, subValue := range mapValue {
2017-11-14 21:45:08 -07:00
if r.Plural {
2017-11-29 14:38:39 -07:00
values.PutValue(data, subValue, subKey, strings.TrimSuffix(key, "s"))
2017-11-14 21:45:08 -07:00
} else {
2017-11-29 14:38:39 -07:00
values.PutValue(data, subValue, subKey, key)
2017-11-14 21:45:08 -07:00
}
2017-11-11 21:14:05 -07:00
}
delete(data, key)
}
}
2017-11-14 21:45:08 -07:00
func (r PivotMapper) ToInternal(data map[string]interface{}) {
2017-11-11 21:14:05 -07:00
for key, value := range data {
mapValue, ok := value.(map[string]interface{})
if !ok {
continue
}
for subKey, subValue := range mapValue {
2017-11-14 21:45:08 -07:00
if r.Plural {
2017-11-29 14:38:39 -07:00
values.PutValue(data, subValue, subKey, key+"s")
2017-11-14 21:45:08 -07:00
} else {
2017-11-29 14:38:39 -07:00
values.PutValue(data, subValue, subKey, key)
2017-11-14 21:45:08 -07:00
}
2017-11-11 21:14:05 -07:00
}
delete(data, key)
}
}
2017-11-14 21:45:08 -07:00
func (r PivotMapper) ModifySchema(schema *types.Schema, schemas *types.Schemas) error {
2017-11-11 21:14:05 -07:00
return nil
}