forked from mirror/gorm
Convert str to int if it is when set field
This commit is contained in:
parent
c387c7d9ba
commit
32dcacc70b
4
model.go
4
model.go
|
@ -5,6 +5,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"reflect"
|
"reflect"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
@ -244,6 +245,9 @@ func setFieldValue(field reflect.Value, value interface{}) {
|
||||||
if field.IsValid() {
|
if field.IsValid() {
|
||||||
switch field.Kind() {
|
switch field.Kind() {
|
||||||
case reflect.Int, reflect.Int32, reflect.Int64:
|
case reflect.Int, reflect.Int32, reflect.Int64:
|
||||||
|
if str, ok := value.(string); ok {
|
||||||
|
value, _ = strconv.Atoi(str)
|
||||||
|
}
|
||||||
field.SetInt(reflect.ValueOf(value).Int())
|
field.SetInt(reflect.ValueOf(value).Int())
|
||||||
default:
|
default:
|
||||||
field.Set(reflect.ValueOf(value))
|
field.Set(reflect.ValueOf(value))
|
||||||
|
|
Loading…
Reference in New Issue