blob: b61b63c21ba5300c3350c426cb03377033c564a6 (
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
|
package model
import (
"fmt"
"strconv"
)
type NumberNode struct {
Value float64
}
func (n NumberNode) Type() NodeType {
return NumberType
}
func (n *NumberNode) MarshalJSON() ([]byte, error) {
return []byte(strconv.FormatFloat(n.Value, 'g', -1, 64)), nil
}
func (n *NumberNode) Set(v any) error {
switch v := v.(type) {
case float64:
n.Value = v
case int:
n.Value = float64(v)
}
return fmt.Errorf("%v is not number", v)
}
|