From d232c69369c25db72812831eb92b34ea9dddcc2c Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Sun, 16 Mar 2014 10:57:38 +0800 Subject: [PATCH] Fix exception in mysql --- main_test.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/main_test.go b/main_test.go index f244c03d..47611908 100644 --- a/main_test.go +++ b/main_test.go @@ -25,17 +25,20 @@ type IgnoredEmbedStruct struct { type Num int64 func (i *Num) Scan(src interface{}) error { - v := reflect.ValueOf(src) - if v.Kind() != reflect.Int64 { - return errors.New("Cannot scan NamedInt from " + v.String()) + switch s := src.(type) { + case []byte: + case int64: + *i = Num(s) + default: + return errors.New("Cannot scan NamedInt from " + reflect.ValueOf(src).String()) } - *i = Num(v.Int()) return nil } type User struct { Id int64 // Id: Primary key Age int64 + UserNum Num Name string `sql:"size:255"` Birthday time.Time // Time CreatedAt time.Time // CreatedAt: Time of record is created, will be insert automatically @@ -53,7 +56,6 @@ type User struct { PasswordHash []byte IgnoreMe int64 `sql:"-"` IgnoreStringSlice []string `sql:"-"` - UserNum Num } type CreditCard struct {