123456789101112131415161718192021222324252627282930313233 |
- package utils
- import "reflect"
- func MergeMaps(destMap, sourceMap map[string]interface{}) map[string]interface{} {
- newMap := make(map[string]interface{})
- // 将目标 map 的元素复制到新 map 中
- for key, value := range destMap {
- newMap[key] = value
- }
- // 将源 map 中的元素合并到新 map 中
- for key, value := range sourceMap {
- newMap[key] = value
- }
- return newMap
- }
- func DeepCopyMap(original map[string]interface{}) map[string]interface{} {
- cloned := make(map[string]interface{})
- for k, v := range original {
- // 检查值是否为引用类型,递归处理
- switch reflect.TypeOf(v).Kind() {
- default:
- // 基本类型直接赋值
- cloned[k] = v
- }
- }
- return cloned
- }
|