Handle byte slice in Scan

Signed-off-by: Émile Ré <nemile.re@gmail.com>
This commit is contained in:
Émile Ré
2025-12-15 17:38:44 +01:00
parent 2f8aef9927
commit 735d91ec18
2 changed files with 31 additions and 19 deletions

View File

@@ -94,10 +94,18 @@ func (gid GID) Timestamp() time.Time {
// Scan implements the database/sql/driver.Scanner interface
func (gid *GID) Scan(value interface{}) error {
var str string
switch v := value.(type) {
case string:
str = v
case []byte:
str = string(v)
default:
return fmt.Errorf("invalid type %T for GID", value)
}
enc := base64.RawURLEncoding
id, err := enc.DecodeString(v)
id, err := enc.DecodeString(str)
if err != nil {
return err
}
@@ -107,9 +115,7 @@ func (gid *GID) Scan(value interface{}) error {
}
copy((*gid)[:], id)
default:
return fmt.Errorf("invalid type for GID: expected string, got %T", value)
}
return nil
}

View File

@@ -53,17 +53,23 @@ func (a *Addr) Scan(value any) error {
return nil
}
var str string
switch v := value.(type) {
case string:
parsed, err := ParseAddr(v)
str = v
case []byte:
str = string(v)
default:
return fmt.Errorf("invalid type %T for mail.Addr", value)
}
parsed, err := ParseAddr(str)
if err != nil {
return err
}
*a = parsed
default:
return fmt.Errorf("invalid type for mail.Addr: expected string, got %T", value)
}
return nil
}