{"id":1249,"date":"2018-08-10T10:46:18","date_gmt":"2018-08-10T15:46:18","guid":{"rendered":"http:\/\/blog.ls-al.com\/?p=1249"},"modified":"2018-08-10T10:46:18","modified_gmt":"2018-08-10T15:46:18","slug":"go-associative-array","status":"publish","type":"post","link":"https:\/\/blog.ls-al.com\/go-associative-array\/","title":{"rendered":"Go Associative Array"},"content":{"rendered":"

Jotting down my test to implement an associative array similar to as my python test here: https:\/\/blog.ls-al.com\/python-dict-for-arrays\/<\/p>\n

In python I used dict and in go I used map.<\/p>\n

\r\n$ pwd\r\n\/home\/rrosso\/src\/examples\r\n\r\n$ cat maps.go \r\npackage main\r\nimport "fmt"\r\ntype rec struct {\r\n\tlname, fname string\r\n}\r\n\r\nvar m map[string]rec\r\n\r\nfunc main() {\r\n\tm = make(map[string]rec)\r\n\tm["1"] = rec{"Sable", "Sam",}\r\n\tm["2"] = rec{"Sable", "Samantha",}\r\n\tm["3"] = rec{"Sable", "Stevie",}\r\n\r\n\tfmt.Println(m)\r\n\tfmt.Println(m["2"])\r\n\tfmt.Println(m["3"].fname)\r\n\tfmt.Println()\r\n\r\n        \/\/simpler example no struct\r\n\tn := map[string]int{"foo": 1, "bar": 2}\r\n    \tfmt.Println("map:", n)\r\n\tfmt.Println("val:", n["bar"])\r\n}\r\n<\/pre>\n

Output<\/p>\n

\r\n$ go run maps.go \r\nmap[1:{Sable Sam} 2:{Sable Samantha} 3:{Sable Stevie}]\r\n{Sable Samantha}\r\nStevie\r\n\r\nmap: map[foo:1 bar:2]\r\nval: 2\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"

Jotting down my test to implement an associative array similar to as my python test here: https:\/\/blog.ls-al.com\/python-dict-for-arrays\/ In python I<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-1249","post","type-post","status-publish","format-standard","hentry","category-go"],"_links":{"self":[{"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/posts\/1249","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/comments?post=1249"}],"version-history":[{"count":0,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/posts\/1249\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/media?parent=1249"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/categories?post=1249"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/tags?post=1249"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}