-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathstruct.go
50 lines (42 loc) · 958 Bytes
/
struct.go
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
45
46
47
48
49
50
package gisk
import (
"errors"
"gopkg.in/yaml.v3"
)
type Value struct {
ValueType ValueType
Value interface{}
}
type RawMessage []byte
func (m RawMessage) MarshalJSON() ([]byte, error) {
if m == nil {
return []byte("null"), nil
}
return m, nil
}
// UnmarshalJSON sets *m to a copy of data.
func (m *RawMessage) UnmarshalJSON(data []byte) error {
if m == nil {
return errors.New("json.RawMessage: UnmarshalJSON on nil pointer")
}
*m = append((*m)[0:0], data...)
return nil
}
func (m RawMessage) MarshalYAML() ([]byte, error) {
if m == nil {
return []byte("null"), nil
}
return m, nil
}
// UnmarshalYAML implements the yaml.Unmarshaler interface for YAMLRawMessage.
func (m *RawMessage) UnmarshalYAML(value *yaml.Node) error {
if m == nil {
return errors.New("yaml.RawMessage: UnmarshalYAML on nil pointer")
}
data, err := yaml.Marshal(value)
if err != nil {
return err
}
*m = append((*m)[0:0], data...)
return nil
}