myMap := make(map[string]int)
//Assign value to a variable myValue, and whether key exists to a variable keyExists.
myValue, keyExists := myMap["myKey"]
//If the key exists, myValue will have its value. and keyExists will be true.
//Otherwise it'll have value 0 and keyExists will be false.
//If you don't care about the value, you can replace myValue with _
_, keyExists := myMap["myKey"]
golang 将func放入go中的地图中
package main
import (
"fmt"
)
//Go program that uses functions closure style inside maps
//makes a map and calls a func from it
func main() {
funcholder := make(map[string]func(a,b int) int)
funcholder["three"] = func(a,b int) int {return a+b}
fmt.Println(funcholder["three"](3, 4))
}
//prints 7