```golang
func MergeMap(mObj ...map[string]string) map[string]string {
newObj := map[string]string{}
for _, m := range mObj {
for k, v := range m {
newObj[k] = v
}
}
return newObj
}
func main() {
extraAttributesMap := map[string]string{
TenantIDKey: "instance.TenantID",
UserIDKey: "instance.UserID",
HostIDKey: "instance.HostID",
StatusKey: "instance.Status",
ProgressKey: "123",
AccessIPv4Key: "instance.AccessIPv4",
FaultKey: "instance.Fault",
}
Metadata := map[string]string{
"1": "11",
"2": "22",
}
extraAttributes := MergeMap(extraAttributesMap, Metadata)
fmt.Println(extraAttributes)
}
```
输出=============================>:
```bash
map[1:11 2:22 AccessIPv4:instance.AccessIPv4 Fault:instance.Fault HostID:instanc
e.HostID Progress:123 Status:instance.Status TenantID:instance.TenantID UserID:i
nstance.UserID]
Process finished with the exit code 0
```
技巧:请在此基础上实现合并过程中的key去重
有疑问加站长微信联系(非本文作者)