2022-11-21 04:31:56 +03:00
|
|
|
package model
|
|
|
|
|
2022-11-21 04:46:32 +03:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strconv"
|
|
|
|
)
|
2022-11-21 04:31:56 +03:00
|
|
|
|
|
|
|
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
|
|
|
|
}
|
2022-11-21 04:46:32 +03:00
|
|
|
|
|
|
|
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)
|
|
|
|
}
|