diff options
author | NeonXP <i@neonxp.dev> | 2022-12-04 16:02:03 +0300 |
---|---|---|
committer | NeonXP <i@neonxp.dev> | 2022-12-04 16:02:03 +0300 |
commit | 6f1d1df79f161cfc695f74d271d689ba72c44d09 (patch) | |
tree | f82a8d091629842613b241ca73f3d4259612f693 | |
parent | 0d431048d3e68609b90306efd9ed015143ae651f (diff) |
Meta data for objectsv0.0.4
-rw-r--r-- | model/node.go | 4 | ||||
-rw-r--r-- | model/objectNode.go | 5 | ||||
-rw-r--r-- | model/types.go | 3 |
3 files changed, 11 insertions, 1 deletions
diff --git a/model/node.go b/model/node.go index 9a55dae..fb6bae5 100644 --- a/model/node.go +++ b/model/node.go @@ -9,6 +9,9 @@ type Node interface { // NewNode creates new node from value func NewNode(value any) Node { + if value, ok := value.(Node); ok { + return value + } switch value := value.(type) { case string: return &StringNode{ @@ -25,6 +28,7 @@ func NewNode(value any) Node { case NodeObjectValue: return &ObjectNode{ Value: value, + Meta: make(map[string]any), } case NodeArrayValue: return &ArrayNode{ diff --git a/model/objectNode.go b/model/objectNode.go index cfa2a30..989fd9e 100644 --- a/model/objectNode.go +++ b/model/objectNode.go @@ -7,6 +7,7 @@ import ( type ObjectNode struct { Value NodeObjectValue + Meta map[string]any } func (n ObjectNode) Type() NodeType { @@ -56,3 +57,7 @@ func (n *ObjectNode) Set(v any) error { n.Value = val return nil } + +func (n *ObjectNode) Remove(key string) { + delete(n.Value, key) +} diff --git a/model/types.go b/model/types.go index bba7527..72dce5f 100644 --- a/model/types.go +++ b/model/types.go @@ -13,6 +13,7 @@ const ( type NodeObjectValue map[string]Node -func (n NodeObjectValue) Set(k string, v any) { +func (n NodeObjectValue) Set(k string, v any) error { n[k] = NewNode(v) + return nil } |