@@ -4,198 +4,209 @@ import "context"
4
4
5
5
// ================ Null ================
6
6
7
- // Null is JSON null struct
8
- type Null struct {}
9
-
10
7
// NullValue is the JSON null value
11
- var NullValue = & Null {}
8
+ var NullValue = & nullT {}
12
9
13
- // Invert returns itself as-is.
14
- func (v * Null ) Invert () (Value , error ) {
15
- return v , nil
10
+ type nullT struct {}
11
+
12
+ func (* nullT ) Invert () (Value , error ) {
13
+ return NullValue , nil
16
14
}
17
15
18
- // Eval returns itself as-is.
19
- func (v * Null ) Eval (context.Context ) (val Value , rollback func (), err error ) {
16
+ func (v * nullT ) Eval (context.Context ) (val Value , rollback func (), err error ) {
20
17
return v , func () {}, nil
21
18
}
22
19
23
- // Type returns the type.
24
- func (v * Null ) Type () Type {
20
+ func (* nullT ) Type () Type {
25
21
return & NullType {}
26
22
}
27
23
28
24
// ================ Bool ================
29
25
26
+ // TrueValue is the JSON true value
27
+ var TrueValue = & boolT {true }
28
+
29
+ // FalseValue is the JSON false value
30
+ var FalseValue = & boolT {false }
31
+
30
32
// Bool is JSON boolean struct
31
- type Bool struct {
32
- value bool
33
+ type Bool interface {
34
+ Value
35
+
36
+ // Value returns the holding internal value
37
+ Value () bool
33
38
}
34
39
35
40
// NewBool creates Bool instance
36
- func NewBool (value bool ) * Bool {
41
+ func NewBool (value bool ) Bool {
37
42
if value {
38
43
return TrueValue
39
44
}
40
45
return FalseValue
41
46
}
42
47
43
- // Value returns the holding internal value
44
- func (v * Bool ) Value () bool {
48
+ type boolT struct {
49
+ value bool
50
+ }
51
+
52
+ func (v * boolT ) Value () bool {
45
53
return v .value
46
54
}
47
55
48
- // Invert returns itself as-is. All literal types of JSON values are the same.
49
- func (v * Bool ) Invert () (Value , error ) {
56
+ func (v * boolT ) Invert () (Value , error ) {
50
57
return v , nil
51
58
}
52
59
53
- // Eval returns itself as-is.
54
- func (v * Bool ) Eval (context.Context ) (val Value , rollback func (), err error ) {
60
+ func (v * boolT ) Eval (context.Context ) (val Value , rollback func (), err error ) {
55
61
return v , func () {}, nil
56
62
}
57
63
58
- // Type returns the type.
59
- func (v * Bool ) Type () Type {
64
+ func (* boolT ) Type () Type {
60
65
return & BoolType {}
61
66
}
62
67
63
- // TrueValue is the JSON true value
64
- var TrueValue = & Bool {true }
65
-
66
- // FalseValue is the JSON false value
67
- var FalseValue = & Bool {false }
68
-
69
68
// ================ Number ================
70
69
71
70
// Number is JSON number struct
72
- type Number struct {
73
- value float64
74
- }
71
+ type Number interface {
72
+ Value
75
73
76
- // Value returns the holding internal value
77
- func (v * Number ) Value () float64 {
78
- return v .value
74
+ // Value returns the holding internal value
75
+ Value () float64
79
76
}
80
77
81
78
// NewNumber creates Number instance
82
- func NewNumber (value float64 ) * Number {
83
- return & Number {value : value }
79
+ func NewNumber (value float64 ) Number {
80
+ return & numberT {value : value }
84
81
}
85
82
86
- // Invert returns itself as-is. All literal types of JSON values are the same.
87
- func (v * Number ) Invert () (Value , error ) {
83
+ type numberT struct {
84
+ value float64
85
+ }
86
+
87
+ func (v * numberT ) Value () float64 {
88
+ return v .value
89
+ }
90
+
91
+ func (v * numberT ) Invert () (Value , error ) {
88
92
return v , nil
89
93
}
90
94
91
- // Eval returns itself as-is.
92
- func (v * Number ) Eval (context.Context ) (val Value , rollback func (), err error ) {
95
+ func (v * numberT ) Eval (context.Context ) (val Value , rollback func (), err error ) {
93
96
return v , func () {}, nil
94
97
}
95
98
96
- // Type returns the type.
97
- func (v * Number ) Type () Type {
99
+ func (* numberT ) Type () Type {
98
100
return & NumberType {}
99
101
}
100
102
101
103
// ================ String ================
102
104
103
105
// String is JSON string struct
104
- type String struct {
105
- value string
106
- }
106
+ type String interface {
107
+ Value
107
108
108
- // Value returns the holding internal value
109
- func (v * String ) Value () string {
110
- return v .value
109
+ // Value returns the holding internal value
110
+ Value () string
111
111
}
112
112
113
113
// NewString creates String instance
114
- func NewString (value string ) * String {
115
- return & String {value : value }
114
+ func NewString (value string ) String {
115
+ return & stringT {value : value }
116
116
}
117
117
118
- // Invert returns itself as-is. All literal types of JSON values are the same.
119
- func (v * String ) Invert () (Value , error ) {
118
+ type stringT struct {
119
+ value string
120
+ }
121
+
122
+ func (v * stringT ) Value () string {
123
+ return v .value
124
+ }
125
+
126
+ func (v * stringT ) Invert () (Value , error ) {
120
127
return v , nil
121
128
}
122
129
123
- // Eval returns itself as-is.
124
- func (v * String ) Eval (context.Context ) (val Value , rollback func (), err error ) {
130
+ func (v * stringT ) Eval (context.Context ) (val Value , rollback func (), err error ) {
125
131
return v , func () {}, nil
126
132
}
127
133
128
- // Type returns the type.
129
- func (v * String ) Type () Type {
134
+ func (* stringT ) Type () Type {
130
135
return & StringType {}
131
136
}
132
137
133
138
// ================ Array ================
134
139
135
140
// Array is JSON array struct
136
- type Array struct {
141
+ type Array interface {
142
+ Value
143
+
144
+ // Value returns the holding internal value.
145
+ // DO NOT CHANGE THE RETURN VALUE DIRECTLY!
146
+ // Copy the slice before changing the value.
147
+ Value () []Value
148
+ }
149
+
150
+ // NewArray creates Array instance
151
+ func NewArray (value []Value , argType Type ) Array {
152
+ return & arrayT {value : value , argType : argType }
153
+ }
154
+
155
+ type arrayT struct {
137
156
value []Value
138
157
argType Type
139
158
}
140
159
141
- // Value returns the holding internal value.
142
- // DO NOT CHANGE THE RETURN VALUE DIRECTLY!
143
- // Copy the slice before changing the value.
144
- func (v * Array ) Value () []Value {
160
+ func (v * arrayT ) Value () []Value {
145
161
return v .value
146
162
}
147
163
148
- // NewArray creates Array instance
149
- func NewArray (value []Value , argType Type ) * Array {
150
- return & Array {value : value , argType : argType }
151
- }
152
-
153
- // Invert returns itself as-is. All literal types of JSON values are the same.
154
- func (v * Array ) Invert () (Value , error ) {
164
+ func (v * arrayT ) Invert () (Value , error ) {
155
165
return v , nil
156
166
}
157
167
158
- // Eval returns itself as-is.
159
- func (v * Array ) Eval (context.Context ) (val Value , rollback func (), err error ) {
168
+ func (v * arrayT ) Eval (context.Context ) (val Value , rollback func (), err error ) {
160
169
return v , func () {}, nil
161
170
}
162
171
163
- // Type returns the type.
164
- func (v * Array ) Type () Type {
172
+ func (v * arrayT ) Type () Type {
165
173
return NewArrayType (v .argType )
166
174
}
167
175
168
176
// ================ Object ================
169
177
170
178
// Object is JSON object struct
171
- type Object struct {
179
+ type Object interface {
180
+ Value
181
+
182
+ // Value returns the holding internal value.
183
+ // DO NOT CHANGE THE RETURN VALUE DIRECTLY!
184
+ // Copy the map instance before changing the value.
185
+ Value () map [string ]Value
186
+ }
187
+
188
+ // NewObject creates Object instance
189
+ func NewObject (value map [string ]Value , argType Type ) Object {
190
+ return & objectT {value : value , argType : argType }
191
+ }
192
+
193
+ type objectT struct {
172
194
value map [string ]Value
173
195
argType Type
174
196
}
175
197
176
- // Value returns the holding internal value.
177
- // DO NOT CHANGE THE RETURN VALUE DIRECTLY!
178
- // Copy the map instance before changing the value.
179
- func (v * Object ) Value () map [string ]Value {
198
+ func (v * objectT ) Value () map [string ]Value {
180
199
return v .value
181
200
}
182
201
183
- // NewObject creates Object instance
184
- func NewObject (value map [string ]Value , argType Type ) * Object {
185
- return & Object {value : value , argType : argType }
186
- }
187
-
188
- // Invert returns itself as-is. All literal types of JSON values are the same.
189
- func (v * Object ) Invert () (Value , error ) {
202
+ func (v * objectT ) Invert () (Value , error ) {
190
203
return v , nil
191
204
}
192
205
193
- // Eval returns itself as-is.
194
- func (v * Object ) Eval (context.Context ) (val Value , rollback func (), err error ) {
206
+ func (v * objectT ) Eval (context.Context ) (val Value , rollback func (), err error ) {
195
207
return v , func () {}, nil
196
208
}
197
209
198
- // Type returns the type.
199
- func (v * Object ) Type () Type {
210
+ func (v * objectT ) Type () Type {
200
211
return NewObjectType (v .argType )
201
212
}
0 commit comments