blob: fb6bae553e6becb0e80fb01c8ae748c311ea190f (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
package model
// Node of JSON tree
type Node interface {
Type() NodeType
MarshalJSON() ([]byte, error)
Set(v any) error
}
// 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{
Value: value,
}
case float64:
return &NumberNode{
Value: value,
}
case int:
return &NumberNode{
Value: float64(value),
}
case NodeObjectValue:
return &ObjectNode{
Value: value,
Meta: make(map[string]any),
}
case NodeArrayValue:
return &ArrayNode{
Value: value,
}
case bool:
return &BooleanNode{
Value: value,
}
default:
return NullNode{}
}
}
|