push
github
4 of 23 new or added lines in 3 files covered. (17.39%)
5884 of 13199 relevant lines covered (44.58%)
298.93 hits per line
1 |
package pgtypes
|
|
2 |
|
|
3 |
import (
|
|
4 |
"database/sql/driver"
|
|
5 |
"fmt"
|
|
6 |
"net/netip"
|
|
7 |
"strings"
|
|
8 |
) |
|
9 |
|
|
10 |
type Inet struct { |
|
11 |
netip.Prefix |
|
12 |
} |
|
13 |
|
|
14 |
// Scan implements the sql.Scanner interface.
|
|
NEW
|
func (i *Inet) Scan(src any) error { |
× |
NEW
|
switch v := src.(type) { |
× |
NEW
|
case []byte: |
× |
NEW
|
return i.Prefix.UnmarshalBinary(v)
|
× |
NEW
|
case string: |
× |
NEW
|
if strings.Contains(v, "/") { |
× |
NEW
|
return i.Prefix.UnmarshalText([]byte(v)) |
× |
NEW
|
} |
× |
NEW
|
addr, err := netip.ParseAddr(v) |
× |
NEW
|
if err != nil { |
× |
NEW
|
return err
|
× |
NEW
|
} |
× |
NEW
|
i.Prefix = netip.PrefixFrom(addr, addr.BitLen()) |
× |
NEW
|
return nil |
× |
NEW
|
default:
|
× |
NEW
|
return fmt.Errorf("cannot scan type %T: %v", src, src) |
× |
31 |
} |
|
32 |
} |
|
33 |
|
|
34 |
// Value implements the driver.Valuer interface.
|
|
NEW
|
func (i Inet) Value() (driver.Value, error) { |
× |
NEW
|
return i.Prefix.MarshalText()
|
× |
NEW
|
} |
× |