forked from mirror/enumer
Merge pull request #32 from vladimiroff/scan-type
Implement Scan with a type switch
This commit is contained in:
commit
3100ad138c
|
@ -1682,14 +1682,16 @@ func (i *Prime) Scan(value interface{}) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
str, ok := value.(string)
|
||||
if !ok {
|
||||
bytes, ok := value.([]byte)
|
||||
if !ok {
|
||||
return fmt.Errorf("value is not a byte slice")
|
||||
}
|
||||
|
||||
str = string(bytes[:])
|
||||
var str string
|
||||
switch v := value.(type) {
|
||||
case []byte:
|
||||
str = string(b)
|
||||
case string:
|
||||
str = v
|
||||
case fmt.Stringer:
|
||||
str = v.String()
|
||||
default:
|
||||
return fmt.Errorf("invalid value of Prime: %[1]T(%[1]v)", value)
|
||||
}
|
||||
|
||||
val, err := PrimeString(str)
|
||||
|
@ -1867,14 +1869,16 @@ func (i *Prime) Scan(value interface{}) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
str, ok := value.(string)
|
||||
if !ok {
|
||||
bytes, ok := value.([]byte)
|
||||
if !ok {
|
||||
return fmt.Errorf("value is not a byte slice")
|
||||
}
|
||||
|
||||
str = string(bytes[:])
|
||||
var str string
|
||||
switch v := value.(type) {
|
||||
case []byte:
|
||||
str = string(b)
|
||||
case string:
|
||||
str = v
|
||||
case fmt.Stringer:
|
||||
str = v.String()
|
||||
default:
|
||||
return fmt.Errorf("invalid value of Prime: %[1]T(%[1]v)", value)
|
||||
}
|
||||
|
||||
val, err := PrimeString(str)
|
||||
|
|
18
sql.go
18
sql.go
|
@ -12,14 +12,16 @@ const scanMethod = `func (i *%[1]s) Scan(value interface{}) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
str, ok := value.(string)
|
||||
if !ok {
|
||||
bytes, ok := value.([]byte)
|
||||
if !ok {
|
||||
return fmt.Errorf("value is not a byte slice")
|
||||
}
|
||||
|
||||
str = string(bytes[:])
|
||||
var str string
|
||||
switch v := value.(type) {
|
||||
case []byte:
|
||||
str = string(b)
|
||||
case string:
|
||||
str = v
|
||||
case fmt.Stringer:
|
||||
str = v.String()
|
||||
default:
|
||||
return fmt.Errorf("invalid value of %[1]s: %%[1]T(%%[1]v)", value)
|
||||
}
|
||||
|
||||
val, err := %[1]sString(str)
|
||||
|
|
Loading…
Reference in New Issue