22 lines
617 B
Go
22 lines
617 B
Go
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
|
|
}
|