Documentation
¶
Index ¶
- func ExtractFieldsV1Object(src map[string]interface{}, fields FieldsV1) (map[string]interface{}, error)
- func FindIndexArrayByKey(obj []interface{}, key FieldsV1Key) int
- func MergeObjects(dst map[string]interface{}, src map[string]interface{}, fields FieldsV1)
- func PurgeRemovedFields(obj map[string]interface{}, removed []FieldsV1) error
- type Conflict
- type FieldManager
- type FieldsType
- type FieldsV1
- type FieldsV1Key
- type FieldsV1KeyType
- type FieldsV1Path
- type FieldsV1Step
- type ManagedFields
- type MergeResult
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExtractFieldsV1Object ¶
func FindIndexArrayByKey ¶
func FindIndexArrayByKey(obj []interface{}, key FieldsV1Key) int
FindIndexArrayByKey takes an array and a FieldsV1Step. It iterates over the array, and if the elements are objects, if checks if the key of the FieldsV1Step matches the object. If it finds the key-object pairing, it returns the index. If it doesn't find the key-object pairing, it returns -1.
func MergeObjects ¶
MergeObjects merges the src map into the dst map according to the fields. It is expected that the fields have been generated from the src object/data.
func PurgeRemovedFields ¶
Types ¶
type Conflict ¶
type Conflict struct { // Fields is a list of fields that are in conflict. Fields []FieldsV1 }
type FieldManager ¶
type FieldManager struct { // Manager is the unique name of the manager. Manager string `json:"manager" cue:"=~\"^[a-zA-Z0-9-_]+$\""` // FieldsType is the type of fields that are managed. // Only supported type is right now is "FieldsV1". FieldsType FieldsType `json:"fieldsType" cue:"=~\"^FieldsV1$\""` // FieldsV1 is the actual fields that are managed. FieldsV1 FieldsV1 `json:"fieldsV1" cue:""` }
FieldManager is a manager of fields for a given object. An object can have multiple field managers, and those field managers make up the managed fields for the object.
type FieldsV1 ¶
type FieldsV1 struct { // Parent is a pointer to the parent field. // It is only used when creating and operating on the managed fields, and // not stored together with the object. Parent *FieldsV1Step `json:"-"` // Fields represents an object, and all of its fields. Fields map[FieldsV1Key]FieldsV1 `json:"-"` // Elements represents an array. // To allow managing indexes of an array, we use a key (not a numerical // index) for the array index. // // The fancy term for this is "associative list". Elements map[FieldsV1Key]FieldsV1 `json:"-"` }
FieldsV1 is the actual fields that are managed.
func ManagedFieldsV1 ¶
func ManagedFieldsV1Object ¶
func ManagedFieldsV1Object( parent *FieldsV1Step, raw map[string]interface{}, ) FieldsV1
func (FieldsV1) IsLeaf ¶
IsLeaf returns true if the field is a leaf node and does not have any fields (object) or elements (array).
func (FieldsV1) MarshalJSON ¶
func (FieldsV1) Path ¶
func (f FieldsV1) Path() FieldsV1Path
Path constructs a path from this node to the root. It only works if the parent is set, which is only the case when creating a FieldsV1.
func (*FieldsV1) UnmarshalJSON ¶
type FieldsV1Key ¶
type FieldsV1Key struct { Type FieldsV1KeyType `json:"-"` Key string `json:"-"` Value string `json:"-"` }
FieldsV1Key represents a key in a FieldsV1 object. It can be either an object key (string) or an array (key-value).
func (FieldsV1Key) MarshalJSON ¶
func (f FieldsV1Key) MarshalJSON() ([]byte, error)
func (FieldsV1Key) String ¶
func (f FieldsV1Key) String() string
func (*FieldsV1Key) UnmarshalJSON ¶
func (f *FieldsV1Key) UnmarshalJSON(data []byte) error
type FieldsV1KeyType ¶
type FieldsV1KeyType int
const ( FieldsV1KeyObject FieldsV1KeyType = iota FieldsV1KeyArray )
type FieldsV1Path ¶
type FieldsV1Path []FieldsV1Step
FieldsV1Path is a series of steps from a node (root) to a leaf node.
func (FieldsV1Path) String ¶
func (p FieldsV1Path) String() string
type FieldsV1Step ¶
type FieldsV1Step struct { Key FieldsV1Key `json:"-"` Field *FieldsV1 `json:"-"` }
func (FieldsV1Step) String ¶
func (s FieldsV1Step) String() string
type ManagedFields ¶
type ManagedFields []FieldManager
func (ManagedFields) FieldManager ¶
func (m ManagedFields) FieldManager(manager string) (FieldManager, bool)
type MergeResult ¶
type MergeResult struct { // ManagedFields is the updated list of field managers after the merge. ManagedFields []FieldManager // Removed contains a list of fields that were previously owned by the field // manager and have been removed in this merge request. Removed []FieldsV1 }
func MergeManagedFields ¶
func MergeManagedFields( managedFields []FieldManager, reqFM FieldManager, force bool, ) (MergeResult, error)