(p interface{})
| 10 | type SizeBytes uint64 |
| 11 | |
| 12 | func (b *SizeBytes) UnmarshalTOML(p interface{}) error { |
| 13 | var actual uint64 |
| 14 | |
| 15 | switch v := p.(type) { |
| 16 | case float64: |
| 17 | if v < 0 { |
| 18 | return fmt.Errorf("invalid size in bytes(%v): value must >= 0", v) |
| 19 | } |
| 20 | if v >= math.MaxUint64 { |
| 21 | return fmt.Errorf("invalid size in bytes (%v): value must be smaller than %v", v, uint64(math.MaxUint64)) |
| 22 | } |
| 23 | actual = uint64(v) |
| 24 | case int64: |
| 25 | if v < 0 { |
| 26 | return fmt.Errorf("invalid size in bytes (%v): value must be >= 0", v) |
| 27 | } |
| 28 | actual = uint64(v) |
| 29 | case string: |
| 30 | if v != "" { |
| 31 | var err error |
| 32 | actual, err = humanize.ParseBytes(v) |
| 33 | if err != nil { |
| 34 | return fmt.Errorf("invalid size in bytes (%v): %v", v, err) |
| 35 | } |
| 36 | } |
| 37 | default: |
| 38 | return fmt.Errorf("unexpected type (%T): unexpected value type", v) |
| 39 | } |
| 40 | *b = SizeBytes(actual) |
| 41 | return nil |
| 42 | } |
nothing calls this directly
no test coverage detected