aboutsummaryrefslogtreecommitdiff
path: root/model/booleanNode.go
blob: aba286e7325767c51c0f9d57a888e9ace895f299 (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
package model

import "fmt"

type BooleanNode struct {
	Value bool
}

func (n BooleanNode) Type() NodeType {
	return BooleanType
}

func (n *BooleanNode) MarshalJSON() ([]byte, error) {
	if n.Value {
		return []byte("true"), nil
	}
	return []byte("false"), nil
}

func (n *BooleanNode) Set(v any) error {
	val, ok := v.(bool)
	if !ok {
		return fmt.Errorf("%v is not boolean", v)
	}
	n.Value = val
	return nil
}