From 32dcacc70ba8894e0720b68f1f74a2c558a9e7c2 Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Fri, 1 Nov 2013 11:17:19 +0800 Subject: [PATCH] Convert str to int if it is when set field --- model.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/model.go b/model.go index 58a63479..b1ffe585 100644 --- a/model.go +++ b/model.go @@ -5,6 +5,7 @@ import ( "fmt" "reflect" "regexp" + "strconv" "time" ) @@ -244,6 +245,9 @@ func setFieldValue(field reflect.Value, value interface{}) { if field.IsValid() { switch field.Kind() { case reflect.Int, reflect.Int32, reflect.Int64: + if str, ok := value.(string); ok { + value, _ = strconv.Atoi(str) + } field.SetInt(reflect.ValueOf(value).Int()) default: field.Set(reflect.ValueOf(value))