In Go, we can create a map with a key and value of type string with the built-in make
function. The make
function takes the type of the map as its argument and returns a map of that type. Here's how we can create a map with string keys and values:
main.go33 chars2 lines
We can then add key-value pairs to the map using the standard syntax:
main.go50 chars3 lines
We can also access values in the map using the key:
main.go45 chars2 lines
Maps are a powerful data structure in Go as they provide a way to associate a key with a value. They are used extensively within Go programs for tasks such as caching and routing.
gistlibby LogSnag