fusenapi/utils/metadata/metadata.go
2023-09-19 12:04:51 +08:00

47 lines
1.3 KiB
Go

package metadata
func SetMetadata(metadataChild map[string]interface{}, oldMetadata map[string]interface{}) (map[string]interface{}, error) {
if oldMetadata != nil {
for k, v := range metadataChild {
switch val := v.(type) {
case map[string]interface{}:
kValue, kEx := oldMetadata[k]
var oldResourceMetadataData map[string]interface{}
if kEx {
oldResourceMetadataData = kValue.(map[string]interface{})
} else {
oldResourceMetadataData = make(map[string]interface{}, len(val))
}
for key1, val1 := range val {
oldResourceMetadataData[key1] = val1
}
oldMetadata[k] = oldResourceMetadataData
default:
oldMetadata[k] = val
}
}
return oldMetadata, nil
} else {
var oldMetadata = make(map[string]interface{}, len(metadataChild))
for k, v := range metadataChild {
switch val := v.(type) {
case map[string]interface{}:
kValue, kEx := oldMetadata[k]
var oldResourceMetadataData map[string]interface{}
if kEx {
oldResourceMetadataData = kValue.(map[string]interface{})
} else {
oldResourceMetadataData = make(map[string]interface{}, len(val))
}
for key, val1 := range val {
oldResourceMetadataData[key] = val1
}
oldMetadata[k] = oldResourceMetadataData
default:
oldMetadata[k] = val
}
}
return oldMetadata, nil
}
}