1
0
mirror of https://github.com/rancher/types.git synced 2025-08-02 05:11:59 +00:00

Update vendor

This commit is contained in:
Darren Shepherd 2017-12-19 22:19:27 -07:00
parent 79db00f1d7
commit 997f09a51c

View File

@ -0,0 +1,45 @@
package mapper
import (
"encoding/json"
"github.com/rancher/norman/types"
"github.com/rancher/norman/types/convert"
"github.com/rancher/norman/types/values"
)
type AnnotationField struct {
Field string
Object bool
}
func (e AnnotationField) FromInternal(data map[string]interface{}) {
v, ok := values.RemoveValue(data, "annotations", "field.cattle.io/"+e.Field)
if ok {
if e.Object {
data := map[string]interface{}{}
//ignore error
if err := json.Unmarshal([]byte(convert.ToString(v)), &data); err == nil {
v = data
}
}
data[e.Field] = v
}
}
func (e AnnotationField) ToInternal(data map[string]interface{}) {
v, ok := data[e.Field]
if ok {
if e.Object {
if bytes, err := json.Marshal(v); err == nil {
v = string(bytes)
}
}
values.PutValue(data, v, "annotations", "field.cattle.io/"+e.Field)
}
}
func (e AnnotationField) ModifySchema(schema *types.Schema, schemas *types.Schemas) error {
return validateField(e.Field, schema)
}