```
package main
//go 1.9 多线程安全MAP 函数模块
//QQ:29295842 欢迎技术交流
import (
// "fmt"
"sync"
)
var (
map_list sync.Map //广告配置信息
wgx sync.WaitGroup //
)
func Thread_map_add(id string, rows_map map[string]interface{}) { //添加数据
map_list.Store(id, rows_map)
}
func Thread_map_revise(id string, rows_map map[string]interface{}) { //修改
wgx.Add(1) //线程数
go func() {
map_list.LoadOrStore(id, rows_map) //修改
wgx.Done()
}()
wgx.Wait() //等待
}
func Thread_map_delete(id string) { //删除
wgx.Add(1) //线程数
go func() {
map_list.Delete(id) //删除
wgx.Done()
}()
wgx.Wait() //等待
}
func Thread_map_read(id string) (bool, string, map[string]interface{}) { //读取
read_bool := false
value := make(map[string]interface{})
value2, err := map_list.Load(id) //key读取
if err {
if valuexa, ok := value2.(map[string]interface{}); ok {
value = valuexa
read_bool = true
}
}
//fmt.Print("===%v==%v==\n", data, err)
//遍历读取
// map_list.Range(func(key, value2 interface{}) bool { //读取数据
// fmt.Println(key, "-----------", value2)
// // if valuexa, ok := value2.(map[string]interface{}); ok {
// // read_bool = true
// // //key = fmt.Sprintf("%v", key)
// // value = valuexa
// // }
// return true
// })
return read_bool, id, value
}
//fmt.Println("----------------")
// rows_map := make(map[string]interface{})
// rows_map["db_name"] = "098765"
// rows_map["list"] = "1234567"
// map_add("abc", rows_map)
// rows_map = make(map[string]interface{})
// rows_map["db_name"] = "aaaaaa"
// rows_map["list"] = "bbbbbbb"
// //map_add("123", rows_map)
// map_revise("abc", rows_map)
// rows_map3 := make(map[string]interface{})
// rows_map3["db_name"] = "rrrrr"
// rows_map3["list"] = "eeeeeee"
// map_add("1234", rows_map3)
// read_bool, key, re_map := map_read("abc")
// fmt.Printf("==%v==%v==%v==\n", read_bool, key, re_map["db_name"])
```
有疑问加站长微信联系(非本文作者))
![](https://static.golangjob.cn/static/img/footer.png?imageView2/2/w/280)