types/model: remove (*Digest).Scan and Digest.Value (#3605)

This commit is contained in:
Blake Mizerany 2024-04-11 13:32:31 -07:00 committed by GitHub
parent c00fee6936
commit 2b341069a7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,10 +1,6 @@
package model
import (
"database/sql"
"database/sql/driver"
"errors"
"fmt"
"log/slog"
"strings"
"unicode"
@ -44,32 +40,9 @@ func (d Digest) LogValue() slog.Value {
}
var (
_ driver.Valuer = Digest{}
_ sql.Scanner = (*Digest)(nil)
_ slog.LogValuer = Digest{}
)
// Scan implements the sql.Scanner interface.
func (d *Digest) Scan(src any) error {
if d.IsValid() {
return errors.New("model.Digest: illegal Scan on valid Digest")
}
switch v := src.(type) {
case string:
*d = ParseDigest(v)
return nil
case []byte:
*d = ParseDigest(string(v))
return nil
}
return fmt.Errorf("model.Digest: invalid Scan source %T", src)
}
// Value implements the driver.Valuer interface.
func (d Digest) Value() (driver.Value, error) {
return d.String(), nil
}
// ParseDigest parses a string in the form of "<digest-type>-<digest>" into a
// Digest.
func ParseDigest(s string) Digest {