Assume we have code:
var Cache_map *map[string]int
Cache_map = new(map[string]int)
Then we want to add key: type
& value 1
into Cache_map
, how shall we do?
If you really, really need to do that, for example,
package main
import "fmt"
func main() {
var Cache_map *map[string]int
Cache_map = new(map[string]int)
*Cache_map = make(map[string]int)
(*Cache_map)["type"] = 1
fmt.Println(*Cache_map)
}
Output:
map[type:1]
No need for new
, make
or a pointer to map in this case. Skeleton/example:
package main
import "fmt"
var CacheMap = map[string]int{}
func main() {
CacheMap["type"] = 1
fmt.Printf("%#v
", CacheMap)
}
Output:
map[string]int{"type":1}