@@ -168,9 +168,14 @@ func (settings Settings) MarshalJSON() ([]byte, error) {
168
168
169
169
// unmarshalScalar
170
170
func unmarshalScalar (untyped interface {}) (string , bool ) {
171
+ var res string
172
+ var ok bool
173
+
171
174
typeOf := reflect .TypeOf (untyped )
172
- str := typeOf .String ()
173
- log .V (3 ).Infof ("%v" , str )
175
+ if typeOf == nil {
176
+ log .V (3 ).Infof ("unmarshalScalar() typeOf==nil" )
177
+ return "" , false
178
+ }
174
179
175
180
switch untyped .(type ) {
176
181
case // scalar
@@ -181,39 +186,57 @@ func unmarshalScalar(untyped interface{}) (string, bool) {
181
186
int64 , uint64 ,
182
187
bool ,
183
188
string :
184
- return fmt .Sprintf ("%v" , untyped ), true
189
+ res = fmt .Sprintf ("%v" , untyped )
190
+ ok = true
185
191
case // scalar
186
192
float32 :
187
193
floatVal := untyped .(float32 )
188
194
_ , frac := math .Modf (float64 (floatVal ))
189
- if frac < ignoreThreshold {
190
- // consider it int
195
+ if frac > ignoreThreshold {
196
+ // Consider it float
197
+ res = fmt .Sprintf ("%f" , untyped )
198
+ } else {
199
+ // Consider it int
191
200
intVal := int64 (floatVal )
192
- return fmt .Sprintf ("%v" , intVal ), true
201
+ res = fmt .Sprintf ("%v" , intVal )
193
202
}
194
- return fmt . Sprintf ( "%f" , untyped ), true
203
+ ok = true
195
204
case // scalar
196
205
float64 :
197
206
floatVal := untyped .(float64 )
198
207
_ , frac := math .Modf (floatVal )
199
- if frac < ignoreThreshold {
200
- // consider it int
208
+ if frac > ignoreThreshold {
209
+ // Consider it float
210
+ res = fmt .Sprintf ("%f" , untyped )
211
+ } else {
212
+ // Consider it int
201
213
intVal := int64 (floatVal )
202
- return fmt .Sprintf ("%v" , intVal ), true
214
+ res = fmt .Sprintf ("%v" , intVal )
203
215
}
204
- return fmt . Sprintf ( "%f" , untyped ), true
216
+ ok = true
205
217
}
206
218
207
- return "" , false
219
+ str := typeOf .String ()
220
+ if ok {
221
+ log .V (3 ).Infof ("unmarshalScalar() type=%v value=%s" , str , res )
222
+ return res , true
223
+ } else {
224
+ log .V (3 ).Infof ("unmarshalScalar() type=%v - UNABLE to unmarshal" , str )
225
+ return "" , false
226
+ }
208
227
}
209
228
210
229
// unmarshalVector
211
230
func unmarshalVector (untyped interface {}) ([]string , bool ) {
231
+ var res []string
232
+ var ok bool
233
+
212
234
typeOf := reflect .TypeOf (untyped )
213
- str := typeOf .String ()
214
- log .V (3 ).Infof ("%v" , str )
235
+ if typeOf == nil {
236
+ log .V (3 ).Infof ("unmarshalVector() typeOf==nil" )
237
+ return nil , false
238
+ }
215
239
216
- var res []string
217
240
switch untyped .(type ) {
218
241
case // vector
219
242
[]interface {}:
@@ -222,10 +245,17 @@ func unmarshalVector(untyped interface{}) ([]string, bool) {
222
245
res = append (res , scalar )
223
246
}
224
247
}
225
- return res , true
248
+ ok = true
226
249
}
227
250
228
- return nil , false
251
+ str := typeOf .String ()
252
+ if ok {
253
+ log .V (3 ).Infof ("unmarshalVector() type=%v value=%s" , str , res )
254
+ return res , true
255
+ } else {
256
+ log .V (3 ).Infof ("unmarshalVector type=%v - UNABLE to unmarshal" , str )
257
+ return nil , false
258
+ }
229
259
}
230
260
231
261
// getValueAsScalar
0 commit comments