mirror of
https://github.com/rancher/types.git
synced 2025-08-02 05:11:59 +00:00
Update vendor
This commit is contained in:
parent
79db00f1d7
commit
997f09a51c
45
vendor/github.com/rancher/norman/types/mapper/annotation_field.go
generated
vendored
Normal file
45
vendor/github.com/rancher/norman/types/mapper/annotation_field.go
generated
vendored
Normal 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)
|
||||
}
|
Loading…
Reference in New Issue
Block a user