Meta data for objects
This commit is contained in:
parent
0d431048d3
commit
6f1d1df79f
3 changed files with 11 additions and 1 deletions
|
@ -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{
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue