aboutsummaryrefslogtreecommitdiff
path: root/model/objectNode.go
diff options
context:
space:
mode:
authorNeonXP <i@neonxp.dev>2022-11-21 04:46:32 +0300
committerNeonXP <i@neonxp.dev>2022-11-21 04:46:32 +0300
commit0d431048d3e68609b90306efd9ed015143ae651f (patch)
tree2a5fe21654bb9af02a0419722f2cd80d588465a2 /model/objectNode.go
parent4054a50ce4232ebfc4dae043863ad96d46b25b43 (diff)
added set method
Diffstat (limited to 'model/objectNode.go')
-rw-r--r--model/objectNode.go15
1 files changed, 10 insertions, 5 deletions
diff --git a/model/objectNode.go b/model/objectNode.go
index 53f500d..cfa2a30 100644
--- a/model/objectNode.go
+++ b/model/objectNode.go
@@ -6,7 +6,7 @@ import (
)
type ObjectNode struct {
- Value map[string]Node
+ Value NodeObjectValue
}
func (n ObjectNode) Type() NodeType {
@@ -30,10 +30,6 @@ func (n *ObjectNode) MarshalJSON() ([]byte, error) {
}, []byte("")), nil
}
-func (n *ObjectNode) Set(k string, v any) {
- n.Value[k] = NewNode(v)
-}
-
func (n *ObjectNode) Get(k string) (Node, error) {
child, ok := n.Value[k]
if !ok {
@@ -51,3 +47,12 @@ func (n *ObjectNode) Merge(n2 *ObjectNode) {
func (n *ObjectNode) Len() int {
return len(n.Value)
}
+
+func (n *ObjectNode) Set(v any) error {
+ val, ok := v.(NodeObjectValue)
+ if !ok {
+ return fmt.Errorf("%v is not object", v)
+ }
+ n.Value = val
+ return nil
+}