You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Drew Bednar 5bd4222342 | 8 months ago | |
---|---|---|
.. | ||
README.md | 8 months ago | |
dictionary.go | 8 months ago | |
dictionary_test.go | 8 months ago | |
go.mod | 8 months ago |
README.md
Maps
https://quii.gitbook.io/learn-go-with-tests/go-fundamentals/maps
Build our own map
Gotcha
A gotcha with maps is that they can be a nil value. A nil map behaves like an empty map when reading, but attempts to write to a nil map will cause a runtime panic. You can read more about maps here.
Therefore, you should never initialize an empty map variable:
var m map[string]string
Instead, you can initialize an empty map like we were doing above, or use the make keyword to create a map for you:
var dictionary = map[string]string{}
// OR
var dictionary = make(map[string]string)