refactor: update user serialization in Yggdrasil handler to use SerializeUser for improved properties handling
Some checks failed
SonarQube Analysis / sonarqube (push) Has been cancelled

This commit is contained in:
lafay
2025-11-30 19:00:59 +08:00
parent 4188ee1555
commit bdd2be5dc5
2 changed files with 19 additions and 6 deletions

View File

@@ -91,8 +91,23 @@ func SerializeUser(logger *zap.Logger, u *model.User, UUID string) map[string]in
}
data := map[string]interface{}{
"id": UUID,
"properties": u.Properties,
"id": UUID,
}
// 正确处理 *datatypes.JSON 指针类型
// 如果 Properties 为 nil则设置为 nil否则解引用并解析为 JSON 值
if u.Properties == nil {
data["properties"] = nil
} else {
// datatypes.JSON 是 []byte 类型,需要解析为实际的 JSON 值
var propertiesValue interface{}
if err := json.Unmarshal(*u.Properties, &propertiesValue); err != nil {
logger.Warn("[WARN] 解析用户Properties失败使用空值", zap.Error(err))
data["properties"] = nil
} else {
data["properties"] = propertiesValue
}
}
return data
}