()
| 326 | func (boolMapper) IsBool() bool { return true } |
| 327 | |
| 328 | func durationDecoder() MapperFunc { |
| 329 | return func(ctx *DecodeContext, target reflect.Value) error { |
| 330 | t, err := ctx.Scan.PopValue("duration") |
| 331 | if err != nil { |
| 332 | return err |
| 333 | } |
| 334 | var d time.Duration |
| 335 | switch v := t.Value.(type) { |
| 336 | case string: |
| 337 | d, err = time.ParseDuration(v) |
| 338 | if err != nil { |
| 339 | return fmt.Errorf("expected duration but got %q: %v", v, err) |
| 340 | } |
| 341 | case int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64, float32, float64: |
| 342 | d = reflect.ValueOf(v).Convert(reflect.TypeOf(time.Duration(0))).Interface().(time.Duration) //nolint: forcetypeassert |
| 343 | default: |
| 344 | return fmt.Errorf("expected duration but got %q", v) |
| 345 | } |
| 346 | target.Set(reflect.ValueOf(d)) |
| 347 | return nil |
| 348 | } |
| 349 | } |
| 350 | |
| 351 | func timeDecoder() MapperFunc { |
| 352 | return func(ctx *DecodeContext, target reflect.Value) error { |
no test coverage detected