create a map with a value of type bool in go

To create a map with a value of type bool in Go, you can use the following code:

main.go
myMap := make(map[string]bool)
31 chars
2 lines

This creates an empty map with string keys and boolean values. You can then add key-value pairs to the map using the following syntax:

main.go
myMap["key1"] = true
myMap["key2"] = false
43 chars
3 lines

You can also initialize a map with values using a map literal:

main.go
myMap := map[string]bool{
    "key1": true,
    "key2": false,
}
65 chars
5 lines

With this code, you can now access the boolean values in the map using the corresponding keys:

main.go
fmt.Println(myMap["key1"]) // true
fmt.Println(myMap["key2"]) // false
71 chars
3 lines

related categories

gistlibby LogSnag