优化mongo,封装count逻辑,处理objectId

This commit is contained in:
2026-01-06 17:01:10 +08:00
parent a43da6e06e
commit 213ad95791
8 changed files with 123 additions and 91 deletions

View File

@@ -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))