Meta data for objects

This commit is contained in:
NeonXP 2022-12-04 16:02:03 +03:00
parent 0d431048d3
commit 6f1d1df79f
No known key found for this signature in database
GPG key ID: B0DA6283C40CB2CB
3 changed files with 11 additions and 1 deletions

View file

@ -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{

View file

@ -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)
}

View file

@ -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
}