json/model/stringNode.go

25 lines
376 B
Go
Raw Normal View History

2022-11-21 04:31:56 +03:00
package model
2022-11-21 04:46:32 +03:00
import "fmt"
2022-11-21 04:31:56 +03:00
type StringNode struct {
Value string
}
func (n StringNode) Type() NodeType {
return StringType
}
func (n *StringNode) MarshalJSON() ([]byte, error) {
return []byte(`"` + n.Value + `"`), nil
}
2022-11-21 04:46:32 +03:00
func (n *StringNode) Set(v any) error {
val, ok := v.(string)
if !ok {
return fmt.Errorf("%v is not string", v)
}
n.Value = val
return nil
}