Questions tagged [go-map]

Go provides a built-in map type that implements a hash table. It is an unordered group of elements of one type, called the element type, indexed by a set of unique keys of another type, called the key type. The value of an uninitialized map is nil. A nil map behaves like an empty map when reading, but attempts to write to a nil map will cause a runtime panic; don't do that.

60 questions
0
votes
1 answer

how to convert map[string]interface{} data to struct

I do not know how to ask, so i will ask with an example. I have some data like that { .. "velocityStatEntries": { "8753": { "estimated": {"value": 23.0,"text": "23.0"}, "completed": {"value": 27.0,"text": "27.0"} …
yabadabaduhast
  • 109
  • 1
  • 6
0
votes
1 answer

using maps with any value type as function parameter?

I am trying to create a function which takes in a map as a parameter, where the map uses string keys but the values can be ANY type. How do I make this work in go? I tried using map[string]interface{} as the parameter type to the function but that…
Atif Ali
  • 2,186
  • 2
  • 12
  • 23
0
votes
1 answer

Building a multi dimentional array reponse

I am trying to create a response like this: "GameController" => [ "methods" => [ "get", "post", "put", "delete" ], ] Following is the script I wrote for this: main.go package main import ( "fmt" …
Anish B
  • 23
  • 2
  • 10
0
votes
0 answers

How to reduce the memory footprint of this go program?

I'm trying to reduce the memory footprint of the code below, which is only about initializing the data I need to then perform a certain set of operations. Pre-allocations are needed. func bToMb(b uint64) uint64 { return b / 1024 / 1024 } func…
Maxwell
  • 105
  • 7
0
votes
2 answers

golang map not adding element

There is battleFoundmap in my code and i tried the add a element like this:(battle is not nil) battleFoundMap[battle.ID] = battle.Answers But when i debug it it returns 1:27: expected '==', found '=' error and not put in it. How to solve it? Here…
aligur
  • 3,387
  • 3
  • 34
  • 51
0
votes
3 answers

Golang iterate over map of interfaces

I am trying to iterate over a map of interfaces in golang, it has the below structure, I am able to use for loop to iterate to a single level but couldn't go deep to get values of the interface. Yaml steps: execute: - mvn : 1.9.3 goals:…
Sudheej
  • 1,873
  • 6
  • 30
  • 57
0
votes
1 answer

What is the best way to create an array and loop in template file

I am using Gin gonic for my Go project, and in my footer.tmpl, I will have more than 10++ navigation links, rather than write 'link' multiple times, it would be much easier if I create an array containing the links, and title and loop through it,…
Charas
  • 1,753
  • 4
  • 21
  • 53
0
votes
1 answer

How can I make a map of parent structs in go?

I'm coming from Java/Kotlin so I'm a bit new to the composition-over-inheritance world that Go is in :) So in Java, I could make a abstract class Pet and a subclass class Dog extends Pet class Cat extends Pet and then make a Map
Michael Shum
  • 2,417
  • 2
  • 11
  • 8
0
votes
3 answers

In Go is there a way to convert map of structure to slice of structure

I have to convert map of structure to slice of structure in Golang, i.e. source to target structure specified below. // Source var source map[string]Category type Category struct { A int SubCategory map[string]SubCategory } type…
Rahul Chawla
  • 190
  • 1
  • 3
  • 14
0
votes
1 answer

How to inject data obtained from result(var) to result1(var) in golang

terraform.tfstate is the input file and packageservicelist.tf.json is the output file. Both are converted into Map Files The data which I traversed is stored in result & I want to copy the data from result to result1. Will Write operations works…
GeekyBoy
  • 15
  • 6
0
votes
1 answer

How to write a struct with nested recursive data in golang

I have data like following { "cars": { "toyota": [ "sedan", "pickup" ], "honda": [ "sedan", "couple", "pickup" ] .... } } The list…
wzcwts521
  • 15
  • 4
0
votes
1 answer

Is writing to a mutex map with multiple goroutines faster than one? and why?

I have a SyncMap defined as follow: type SyncMap struct { sync.Mutex Map map[int]string } And, now I write to it using two ways, one goroutine and multiple goroutines with mutex. codes as follow: smap := SyncMap{} smap.Map =…
Alexander
  • 523
  • 5
  • 21
0
votes
1 answer

is there Guava table equivalent in Golang? if not what is the right way of doing in Go

I want something like this in go table map[string]table what I have tired for map[string]table is mentioned below but not sure if its the right approach: package main import ( "fmt" ) type table struct{ a,b []int c []string } func…
Junaid s
  • 89
  • 6
0
votes
1 answer

golang de-reference a map

Here is a sample code that creates a Map of string keys having value of bool. myMap := make(map[string]bool) myMap["Jan"] = true myMap["Feb"] = false myMap["Mar"] = true After doing some operation on this map, I want to delete it. I don't want to…
Deepak Kumar
  • 426
  • 7
  • 20
-1
votes
1 answer

Transform a golang map into another structure of map

I need help for transforming this input map into the output map. I try with switch/case and for but I didn't succeed it. Thanks a lot ! Input : Values{ "toto_voiture_brand": Ad{ "CITROEN": "CITROEN", …
Mona
  • 21
  • 5