aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--model/node.go4
-rw-r--r--model/objectNode.go5
-rw-r--r--model/types.go3
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
}