优化mongo,封装count逻辑,处理objectId
This commit is contained in:
@@ -107,7 +107,34 @@ func GetUserInfo(ctx context.Context) (user beans.User, err error) {
|
||||
}
|
||||
return
|
||||
}
|
||||
func SetValue(ctx context.Context, result any, key string, value any) {
|
||||
// 检查context是否已取消
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return
|
||||
default:
|
||||
// 使用反射设置result的Total属性
|
||||
resultValue := reflect.ValueOf(result)
|
||||
if resultValue.Kind() == reflect.Ptr {
|
||||
resultValue = resultValue.Elem()
|
||||
totalField := resultValue.FieldByName(key)
|
||||
if totalField.IsValid() && totalField.CanSet() {
|
||||
totalField.Set(reflect.ValueOf(value))
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
func Struts(ctx context.Context, pointer any, mapping ...map[string]string) {
|
||||
// 检查context是否已取消
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return
|
||||
default:
|
||||
|
||||
return
|
||||
}
|
||||
}
|
||||
func OrderMap(m map[string]interface{}) map[string]interface{} {
|
||||
// 提取所有key
|
||||
keys := make([]string, 0, len(m))
|
||||
|
||||
Reference in New Issue
Block a user