DevOps Articles

Curated articles, resources, tips and trends from the DevOps World.

Golang Maps

5 years ago medium.com
Golang Maps

Summary: This is a summary of an article originally published by the source. Read the full original article here →

how to create, update, delete and loop through golang maps A map is a builtin type in Go that is used to store key-value pairs, where each key is unique. all the individual keys needs to be a particular type and all the individual values of another type although the keys and values can be of different types.

The syntax for adding new items to a map is the same as that of arrays, if you try to add to maps which have not been initialised it will result in “panic: assignment to entry in nil map” lets create a function(printMap) below to loop through the values of a map which gets passed as reference.

Before retrieving a single value we want to check if that key-value exists in the map, below code show how to check and retrieve at the same time

Made with pure grit © 2024 Jetpack Labs Inc. All rights reserved. www.jetpacklabs.com