Scan implements database/sql.Scanner.
(src any)
| 59 | |
| 60 | // Scan implements database/sql.Scanner. |
| 61 | func (b *Bool) Scan(src any) error { |
| 62 | if src == nil { |
| 63 | *b = "" |
| 64 | return nil |
| 65 | } |
| 66 | switch src := src.(type) { |
| 67 | case bool: |
| 68 | if src { |
| 69 | *b = True |
| 70 | } else { |
| 71 | *b = False |
| 72 | } |
| 73 | return nil |
| 74 | case int64: |
| 75 | if src == 0 { |
| 76 | *b = False |
| 77 | } else { |
| 78 | *b = True |
| 79 | } |
| 80 | return nil |
| 81 | default: |
| 82 | return fmt.Errorf("opt.Bool.Scan: invalid type %T: %v", src, src) |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | // Normalized returns the normalized form of b, mapping "unset" to "" |
| 87 | // and leaving other values unchanged. |