temp
This commit is contained in:
21
apps/api/internal/common/logic.go
Normal file
21
apps/api/internal/common/logic.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package common
|
||||
|
||||
func MapStructToAPIRequest(encryptedFields map[string]interface{}, fieldMapping map[string]string, wrapField string) map[string]interface{} {
|
||||
apiRequest := make(map[string]interface{})
|
||||
|
||||
// 遍历字段映射表
|
||||
for structField, apiField := range fieldMapping {
|
||||
// 如果加密后的字段存在,才添加到请求
|
||||
if value, exists := encryptedFields[structField]; exists {
|
||||
apiRequest[apiField] = value
|
||||
}
|
||||
}
|
||||
|
||||
// 如果 wrapField 不为空,将 apiRequest 包裹到该字段下
|
||||
if wrapField != "" {
|
||||
return map[string]interface{}{
|
||||
wrapField: apiRequest,
|
||||
}
|
||||
}
|
||||
return apiRequest
|
||||
}
|
||||
Reference in New Issue
Block a user