refactor: update user serialization in Yggdrasil handler to use SerializeUser for improved properties handling
Some checks failed
SonarQube Analysis / sonarqube (push) Has been cancelled
Some checks failed
SonarQube Analysis / sonarqube (push) Has been cancelled
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user