Go 「 Trying to make you to fall in love with Golang 」 1 / 9 Maps Luca Sepe Software Craftsman, Solution Architect, Trainer https://twitter.com/lucasepe/ https://github.com/lucasepe/ https://lucasepe.it/
key- value pairs. keys are unique while the values may not used for fast lookups, retrieval, and deletion of data based on keys In Go a map is declared using the following syntax: var m map[keyType]valType Try It 「Trying to make you to fall in love with Golang」 - Maps 2 / 9 Maps Luca Sepe Software Craftsman, Solution Architect, Trainer https://twitter.com/lucasepe/ https://github.com/lucasepe/ https://lucasepe.it/
is comparable. boolean, numeric, string, pointer channel and interface types structs or arrays that contain only those types 「Trying to make you to fall in love with Golang」 - Maps 3 / 9 Maps Luca Sepe Software Craftsman, Solution Architect, Trainer https://twitter.com/lucasepe/ https://github.com/lucasepe/ https://lucasepe.it/
m = make(map[string]int) using a map literal: var m = map[string]float64{ "Margherita": 5.00, "Calzone": 7.50, "Diavola": 6.50, // <- Mind this comma! } Try It! 「Trying to make you to fall in love with Golang」 - Maps 4 / 9 Maps Luca Sepe Software Craftsman, Solution Architect, Trainer https://twitter.com/lucasepe/ https://github.com/lucasepe/ https://lucasepe.it/
key using the syntax: m[key] if the key does not exists we will get the zero value of value type How to check if a key exists? Use the following two-value assignment val, ok := m[key] the boolean variable ok will be true if the key exists Try It! 5 / 9 Maps Luca Sepe Software Craftsman, Solution Architect, Trainer https://twitter.com/lucasepe/ https://github.com/lucasepe/ https://lucasepe.it/
range loop the iteration order is undefined, non-deterministic and non-reproducible Deleting an item Use the built-in delete function does not return any value if the key does not exist it does not do anything Try It! 6 / 9 Maps Luca Sepe Software Craftsman, Solution Architect, Trainer https://twitter.com/lucasepe/ https://github.com/lucasepe/ https://lucasepe.it/
is a requirement we must maintain a separate data structure that specifies that order Try It! 「Trying to make you to fall in love with Golang」 - Maps 7 / 9 Maps Luca Sepe Software Craftsman, Solution Architect, Trainer https://twitter.com/lucasepe/ https://github.com/lucasepe/ https://lucasepe.it/
map is just a pointer to a runtime.hmap struct So pay attention when you assign the same map to others variables they both refer to the same underlying data structure Try It! 8 / 9 Maps Luca Sepe Software Craftsman, Solution Architect, Trainer https://twitter.com/lucasepe/ https://github.com/lucasepe/ https://lucasepe.it/
(@night) {twitter.com, github.com, linkedin.com} / lucasepe 「Trying to make you to fall in love with Golang」 - Maps 9 / 9 Maps Luca Sepe Software Craftsman, Solution Architect, Trainer https://twitter.com/lucasepe/ https://github.com/lucasepe/ https://lucasepe.it/