mirror of
https://github.com/mainnika/mongox-go-driver.git
synced 2026-06-12 16:53:35 +00:00
Use err type for panics
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package base
|
package base
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"reflect"
|
"reflect"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -19,7 +20,7 @@ func Reset(target interface{}) {
|
|||||||
|
|
||||||
v := reflect.ValueOf(target)
|
v := reflect.ValueOf(target)
|
||||||
if v.Kind() != reflect.Ptr {
|
if v.Kind() != reflect.Ptr {
|
||||||
panic("reset target should be a pointer")
|
panic(fmt.Errorf("reset target should be a pointer"))
|
||||||
}
|
}
|
||||||
|
|
||||||
t := v.Elem().Type()
|
t := v.Elem().Type()
|
||||||
|
|||||||
@@ -142,7 +142,7 @@ func (d *Database) createAggregateLoad(target interface{}, composed *query.Query
|
|||||||
}
|
}
|
||||||
jsonTag, ok := tag.Lookup("json")
|
jsonTag, ok := tag.Lookup("json")
|
||||||
if jsonTag == "-" {
|
if jsonTag == "-" {
|
||||||
return nil, fmt.Errorf("preload private field is impossible")
|
panic(fmt.Errorf("preload private field is impossible"))
|
||||||
}
|
}
|
||||||
|
|
||||||
jsonData := strings.SplitN(jsonTag, ",", 2)
|
jsonData := strings.SplitN(jsonTag, ",", 2)
|
||||||
@@ -156,7 +156,7 @@ func (d *Database) createAggregateLoad(target interface{}, composed *query.Query
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if len(preloadData) == 1 {
|
if len(preloadData) == 1 {
|
||||||
panic("there is no foreign field")
|
panic(fmt.Errorf("there is no foreign field"))
|
||||||
}
|
}
|
||||||
|
|
||||||
localField := strings.TrimSpace(preloadData[0])
|
localField := strings.TrimSpace(preloadData[0])
|
||||||
@@ -166,7 +166,7 @@ func (d *Database) createAggregateLoad(target interface{}, composed *query.Query
|
|||||||
|
|
||||||
foreignField := strings.TrimSpace(preloadData[1])
|
foreignField := strings.TrimSpace(preloadData[1])
|
||||||
if len(foreignField) == 0 {
|
if len(foreignField) == 0 {
|
||||||
panic("there is no foreign field")
|
panic(fmt.Errorf("there is no foreign field"))
|
||||||
}
|
}
|
||||||
|
|
||||||
preloadLimiter := 100
|
preloadLimiter := 100
|
||||||
@@ -198,7 +198,7 @@ func (d *Database) createAggregateLoad(target interface{}, composed *query.Query
|
|||||||
typ = typ.Elem()
|
typ = typ.Elem()
|
||||||
}
|
}
|
||||||
if typ.Kind() != reflect.Ptr {
|
if typ.Kind() != reflect.Ptr {
|
||||||
panic("preload field should have ptr type")
|
panic(fmt.Errorf("preload field should have ptr type"))
|
||||||
}
|
}
|
||||||
|
|
||||||
lookupCollection := d.GetCollectionOf(reflect.Zero(typ).Interface())
|
lookupCollection := d.GetCollectionOf(reflect.Zero(typ).Interface())
|
||||||
|
|||||||
Reference in New Issue
Block a user