package main
import "fmt"
func modifyUser(users map[string]map[string]string, name string) {
/*
如果name存在,则修改密码为 8888888
如果不存在,则存储 nickname 和 password
*/
// val, ok = users[name]
if users[name] != nil {
users[name]["password"] = "8888888"
} else {
// 先make, 分配内存
users[name] = make(map[string]string)
// 存储信息
users[name]["nickname"] = name
users[name]["password"] = "8888888"
}
}
func main() {
// 练习
users := make(map[string]map[string]string, 10)
fmt.Println("users = ", users)
modifyUser(users, "xiao")
fmt.Println("修改后users = ", users) // map[xiao:map[nickname:xiao password:8888888]]
}