1
0
mirror of https://github.com/rancher/types.git synced 2025-06-27 22:16:48 +00:00
types/mapper/resource.go

53 lines
1.0 KiB
Go
Raw Normal View History

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