@@ -85,7 +85,7 @@ func (d *decoder) parseMapData() {
8585 l = len (d .dm ) + 1
8686
8787 if l > cap (d .dm ) {
88- dm := make (dataMap , l , l )
88+ dm := make (dataMap , l )
8989 copy (dm , d .dm )
9090 rd = new (recursiveData )
9191 dm [len (d .dm )] = rd
@@ -180,15 +180,13 @@ func (d *decoder) traverseStruct(v reflect.Value, typ reflect.Type, namespace []
180180func (d * decoder ) setFieldByType (current reflect.Value , namespace []byte , idx int ) (set bool ) {
181181
182182 var err error
183-
184183 v , kind := ExtractType (current )
185184
186185 arr , ok := d .values [string (namespace )]
187186
188187 if d .d .customTypeFuncs != nil {
189188
190189 if ok {
191-
192190 if cf , ok := d .d .customTypeFuncs [v .Type ()]; ok {
193191 val , err := cf (arr )
194192 if err != nil {
@@ -202,10 +200,14 @@ func (d *decoder) setFieldByType(current reflect.Value, namespace []byte, idx in
202200 }
203201 }
204202 }
205-
206203 switch kind {
207- case reflect .Interface , reflect .Invalid :
208- return
204+ case reflect .Interface :
205+ if ! ok {
206+ return
207+ }
208+ v .Set (reflect .ValueOf (arr [idx ]))
209+ set = true
210+
209211 case reflect .Ptr :
210212
211213 newVal := reflect .New (v .Type ().Elem ())
@@ -214,188 +216,145 @@ func (d *decoder) setFieldByType(current reflect.Value, namespace []byte, idx in
214216 }
215217
216218 case reflect .String :
217-
218219 if ! ok {
219220 return
220221 }
221-
222222 v .SetString (arr [idx ])
223223 set = true
224224
225225 case reflect .Uint , reflect .Uint64 :
226-
227226 if ! ok || len (arr [idx ]) == 0 {
228227 return
229228 }
230-
231229 var u64 uint64
232-
233230 if u64 , err = strconv .ParseUint (arr [idx ], 10 , 64 ); err != nil {
234231 d .setError (namespace , fmt .Errorf ("Invalid Unsigned Integer Value '%s' Type '%v' Namespace '%s'" , arr [idx ], v .Type (), string (namespace )))
235232 return
236233 }
237-
238234 v .SetUint (u64 )
239235 set = true
240236
241237 case reflect .Uint8 :
242-
243238 if ! ok || len (arr [idx ]) == 0 {
244239 return
245240 }
246-
247241 var u64 uint64
248-
249242 if u64 , err = strconv .ParseUint (arr [idx ], 10 , 8 ); err != nil {
250243 d .setError (namespace , fmt .Errorf ("Invalid Unsigned Integer Value '%s' Type '%v' Namespace '%s'" , arr [idx ], v .Type (), string (namespace )))
251244 return
252245 }
253-
254246 v .SetUint (u64 )
255247 set = true
256248
257249 case reflect .Uint16 :
258-
259250 if ! ok || len (arr [idx ]) == 0 {
260251 return
261252 }
262-
263253 var u64 uint64
264-
265254 if u64 , err = strconv .ParseUint (arr [idx ], 10 , 16 ); err != nil {
266255 d .setError (namespace , fmt .Errorf ("Invalid Unsigned Integer Value '%s' Type '%v' Namespace '%s'" , arr [idx ], v .Type (), string (namespace )))
267256 return
268257 }
269-
270258 v .SetUint (u64 )
271259 set = true
272260
273261 case reflect .Uint32 :
274-
275262 if ! ok || len (arr [idx ]) == 0 {
276263 return
277264 }
278-
279265 var u64 uint64
280-
281266 if u64 , err = strconv .ParseUint (arr [idx ], 10 , 32 ); err != nil {
282267 d .setError (namespace , fmt .Errorf ("Invalid Unsigned Integer Value '%s' Type '%v' Namespace '%s'" , arr [idx ], v .Type (), string (namespace )))
283268 return
284269 }
285-
286270 v .SetUint (u64 )
287271 set = true
288272
289273 case reflect .Int , reflect .Int64 :
290274 if ! ok || len (arr [idx ]) == 0 {
291275 return
292276 }
293-
294277 var i64 int64
295-
296278 if i64 , err = strconv .ParseInt (arr [idx ], 10 , 64 ); err != nil {
297279 d .setError (namespace , fmt .Errorf ("Invalid Integer Value '%s' Type '%v' Namespace '%s'" , arr [idx ], v .Type (), string (namespace )))
298280 return
299281 }
300-
301282 v .SetInt (i64 )
302283 set = true
303284
304285 case reflect .Int8 :
305286 if ! ok || len (arr [idx ]) == 0 {
306287 return
307288 }
308-
309289 var i64 int64
310-
311290 if i64 , err = strconv .ParseInt (arr [idx ], 10 , 8 ); err != nil {
312291 d .setError (namespace , fmt .Errorf ("Invalid Integer Value '%s' Type '%v' Namespace '%s'" , arr [idx ], v .Type (), string (namespace )))
313292 return
314293 }
315-
316294 v .SetInt (i64 )
317295 set = true
318296
319297 case reflect .Int16 :
320298 if ! ok || len (arr [idx ]) == 0 {
321299 return
322300 }
323-
324301 var i64 int64
325-
326302 if i64 , err = strconv .ParseInt (arr [idx ], 10 , 16 ); err != nil {
327303 d .setError (namespace , fmt .Errorf ("Invalid Integer Value '%s' Type '%v' Namespace '%s'" , arr [idx ], v .Type (), string (namespace )))
328304 return
329305 }
330-
331306 v .SetInt (i64 )
332307 set = true
333308
334309 case reflect .Int32 :
335310 if ! ok || len (arr [idx ]) == 0 {
336311 return
337312 }
338-
339313 var i64 int64
340-
341314 if i64 , err = strconv .ParseInt (arr [idx ], 10 , 32 ); err != nil {
342315 d .setError (namespace , fmt .Errorf ("Invalid Integer Value '%s' Type '%v' Namespace '%s'" , arr [idx ], v .Type (), string (namespace )))
343316 return
344317 }
345-
346318 v .SetInt (i64 )
347319 set = true
348320
349321 case reflect .Float32 :
350-
351322 if ! ok || len (arr [idx ]) == 0 {
352323 return
353324 }
354-
355325 var f float64
356-
357326 if f , err = strconv .ParseFloat (arr [idx ], 32 ); err != nil {
358327 d .setError (namespace , fmt .Errorf ("Invalid Float Value '%s' Type '%v' Namespace '%s'" , arr [0 ], v .Type (), string (namespace )))
359328 return
360329 }
361-
362330 v .SetFloat (f )
363331 set = true
364332
365333 case reflect .Float64 :
366-
367334 if ! ok || len (arr [idx ]) == 0 {
368335 return
369336 }
370-
371337 var f float64
372-
373338 if f , err = strconv .ParseFloat (arr [idx ], 64 ); err != nil {
374339 d .setError (namespace , fmt .Errorf ("Invalid Float Value '%s' Type '%v' Namespace '%s'" , arr [0 ], v .Type (), string (namespace )))
375340 return
376341 }
377-
378342 v .SetFloat (f )
379343 set = true
380344
381345 case reflect .Bool :
382-
383346 if ! ok {
384347 return
385348 }
386-
387349 var b bool
388-
389350 if b , err = parseBool (arr [idx ]); err != nil {
390351 d .setError (namespace , fmt .Errorf ("Invalid Boolean Value '%s' Type '%v' Namespace '%s'" , arr [idx ], v .Type (), string (namespace )))
391352 return
392353 }
393-
394354 v .SetBool (b )
395355 set = true
396356
397357 case reflect .Slice , reflect .Array :
398-
399358 if ! ok {
400359
401360 d .parseMapData ()
@@ -504,7 +463,6 @@ func (d *decoder) setFieldByType(current reflect.Value, namespace []byte, idx in
504463 v .Set (varr )
505464
506465 case reflect .Map :
507-
508466 var rd * recursiveData
509467
510468 d .parseMapData ()
@@ -551,7 +509,6 @@ func (d *decoder) setFieldByType(current reflect.Value, namespace []byte, idx in
551509 v .Set (mp )
552510
553511 case reflect .Struct :
554-
555512 typ := v .Type ()
556513
557514 // if we get here then no custom time function declared so use RFC3339 by default
@@ -580,7 +537,6 @@ func (d *decoder) setFieldByType(current reflect.Value, namespace []byte, idx in
580537
581538 set = d .traverseStruct (v , typ , namespace )
582539 }
583-
584540 return
585541}
586542
0 commit comments