nil lookup fix

This commit is contained in:
Sebastian Frank 2022-07-25 10:24:56 +02:00
parent 09b3faa8da
commit 03b83d3fb9

View File

@ -156,10 +156,14 @@ func Lookup(db *mgo.Database, structField string, results interface{}, selector
object := objectIDs[objectID]
field := elV.FieldByName(structField)
if fieldIsPtr {
field.Set(reflect.ValueOf(object))
} else {
field.Set(reflect.ValueOf(object).Elem())
if object != nil && field.CanSet() {
objectVal := reflect.ValueOf(object)
if fieldIsPtr {
field.Set(objectVal)
} else {
field.Set(objectVal.Elem())
}
}
}