mirror of
https://github.com/astaxie/beego.git
synced 2025-07-03 18:10:19 +00:00
add support for time.Time pointer in struct types
Allow to use pointer *time.Time as a type in combination with orm tags in struct. This enables to treat them as "empty" in JSON marshaling/unmarshaling when using 'json:"null,omitempty'.
This commit is contained in:
11
orm/db.go
11
orm/db.go
@ -243,6 +243,9 @@ func (d *dbBase) collectFieldValue(mi *modelInfo, fi *fieldInfo, ind reflect.Val
|
||||
if fi.isFielder {
|
||||
f := field.Addr().Interface().(Fielder)
|
||||
f.SetRaw(tnow.In(DefaultTimeLoc))
|
||||
} else if field.Kind() == reflect.Ptr {
|
||||
v := tnow.In(DefaultTimeLoc)
|
||||
field.Set(reflect.ValueOf(&v))
|
||||
} else {
|
||||
field.Set(reflect.ValueOf(tnow.In(DefaultTimeLoc)))
|
||||
}
|
||||
@ -1273,8 +1276,14 @@ setValue:
|
||||
if isNative {
|
||||
if value == nil {
|
||||
value = time.Time{}
|
||||
} else if field.Kind() == reflect.Ptr {
|
||||
if value != nil {
|
||||
v := value.(time.Time)
|
||||
field.Set(reflect.ValueOf(&v))
|
||||
}
|
||||
} else {
|
||||
field.Set(reflect.ValueOf(value))
|
||||
}
|
||||
field.Set(reflect.ValueOf(value))
|
||||
}
|
||||
case fieldType == TypePositiveBitField && field.Kind() == reflect.Ptr:
|
||||
if value != nil {
|
||||
|
Reference in New Issue
Block a user