You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
623 B
32 lines
623 B
2 years ago
|
package dorm
|
||
3 years ago
|
|
||
3 years ago
|
type SliceResult struct {
|
||
|
Result []interface{}
|
||
|
Err error
|
||
|
}
|
||
|
|
||
3 years ago
|
// NewSliceResult 构造函数
|
||
3 years ago
|
func NewSliceResult(result []interface{}, err error) *SliceResult {
|
||
|
return &SliceResult{Result: result, Err: err}
|
||
|
}
|
||
|
|
||
|
// Unwrap 空值情况下返回错误
|
||
|
func (r *SliceResult) Unwrap() []interface{} {
|
||
|
if r.Err != nil {
|
||
3 years ago
|
panic(r.Err)
|
||
3 years ago
|
}
|
||
|
return r.Result
|
||
|
}
|
||
|
|
||
|
// UnwrapOr 空值情况下设置返回默认值
|
||
|
func (r *SliceResult) UnwrapOr(defaults []interface{}) []interface{} {
|
||
|
if r.Err != nil {
|
||
|
return defaults
|
||
|
}
|
||
|
return r.Result
|
||
|
}
|
||
|
|
||
|
func (r *SliceResult) Iter() *Iterator {
|
||
|
return NewIterator(r.Result)
|
||
|
}
|