Skip to main content
Filter by
Sorted by
Tagged with
2 votes
2 answers
146 views

I'm looking for a way to cache data using a map (or equivalent) but instead of a comparable key (like int, string, etc) it would be lower and upper time boundaries. I would then be able to perform a ...
Jeff's user avatar
  • 602
1 vote
1 answer
107 views

I'm using WP Go Maps Pro plugin. I'm trying to add a click event listener to a google map marker. I get all the markers infos, but for some reason it won't add the listener. Any idea what I'm doing ...
Rom's user avatar
  • 133
0 votes
0 answers
161 views

I have a use case where the input payload consumed by my REST endpoint should flush it in the same order. There is no specific pattern to the input, so I'm saving it as map[string]interface{} and that ...
ArigatoManga's user avatar
0 votes
0 answers
360 views

I want to append to slice in map which is defined as map[any]any I am having type conversion issues and don't know how to treat result[index][ABSPath] as slice so I can append data to it Here is the ...
John Doe's user avatar
0 votes
1 answer
87 views

I am working on a simple Console game to learn Go and got stuck on a seemingly simple issue that would be no problem in other languages, but seems almost impossible in Go. I have a map of interfaces ...
matronator's user avatar
2 votes
0 answers
1k views

I just would like to do like the below about validation on Gin(Golang). type Accounts struct { Accounts []*Account `json:"accounts" binding:"required,dive"` } type Account ...
TomoEno's user avatar
  • 21
1 vote
1 answer
53 views

I've been trying to solve Advent of Code 2021 and in day 6, I am trying this solution but the result is different everytime. What seems to be the problem? Is there any memory leakage with map? The ...
Kanuor's user avatar
  • 45
-1 votes
1 answer
282 views

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&...
Mona's user avatar
  • 23
0 votes
0 answers
99 views

This is a beginner question about why I get such a result when trying to obtain a Map from a Slice in go lang. I have this code: func (p *ProductsStruct) ToMap() map[int32]*Product { result := map[...
Lupascu Gabriel Cristian's user avatar
0 votes
1 answer
155 views

I'm trying to normalize a structure from a CSV file, which is like this: name, note 'Joe', 5 'Joe', 3 'Ashley', 1 'Ashley', 7 'Ashley', 4 to a map, that after read that file, will be reduced to: map [...
Alan Barbiero's user avatar
3 votes
1 answer
115 views

i was making a web scraper with colly package, where it collects the ContestName and ContestTime from a website and make a json file. so i did like this Contests := make(map[string]map[string]map[...
Vinay Kumar Rasala's user avatar
0 votes
1 answer
124 views

I am trying to run the following code to query in BQ passing labels in GoLang, but getting panic error (You may refer attached image for linenumbers). I am new to Golang, can someone please guide here?...
newbie's user avatar
  • 5
-3 votes
1 answer
157 views

In my project we are using nested map map[string]map[string]map[string]string for insertion of the data into cache. While preparing the data the db data has to be compared with the cache data(nested ...
madhusri mannuru's user avatar
1 vote
1 answer
678 views

I try to firgure out that what determines the order of results generated from "for range" iteration of golang map. I found that it is neither determined by the order of keys nor by the order ...
Tsiao Wang's user avatar
0 votes
1 answer
2k views

I have a simple struct and receiver. I try to set the map with the struct and then call the receiver. Like that: package main import ( "fmt" ) type myStruct struct { FirstName ...
user63898's user avatar
  • 31.1k
1 vote
0 answers
525 views

GO version: 1.18.3 Mongodb version: 4.4 Mongodb driver used: go.mongodb.org/mongo-driver/bson I want to receive an embedded object saved in the database in the form of a map with preserved order (...
Amandeep kaur's user avatar
-1 votes
1 answer
147 views

Im trying to create a map that remembers its values when the page is recalled. I declared it outside the function so it would remain the same but the map still initializes to the defauly=t values when ...
jcezetah's user avatar
3 votes
1 answer
12k views

can i create in golang a map with any key type and any value type ? , something like : dict1 := map[interface]interface{} Thanks a lot !
Edgar's user avatar
  • 43
1 vote
2 answers
957 views

Why does Go's slice has 'replication trap', but map does not? Suppose we have a function that takes slice as an input parameter, and if slice is expanded in the function, only the copied slice ...
qizong007's user avatar
-1 votes
1 answer
701 views

I have the following struct that contains channels and a map for storage of data. I want to be able to pass that struct into functions in order to make use of those channels so that once they are ...
AC007's user avatar
  • 135
-3 votes
1 answer
579 views

I have below snippet func fakeGetInclusterConfig() (*corev1.ConfigMap, error) { configMap := &corev1.ConfigMap{ Data: map[string]map[string]string{"cluster-config.json&...
ambikanair's user avatar
  • 4,720
0 votes
1 answer
6k views

I do not know how to ask, so i will ask with an example. I have some data like that { .. "velocityStatEntries": { "8753": { "estimated": {"value&...
yabadabaduhast's user avatar
6 votes
1 answer
2k views

To know a key k exist in a map M1[k]v is very straightforward in Go. if v, ok := M1[k]; ok { // key exist } 'v': a value of a non-pointer type. If v is large, To just check if a particular key ...
Prakash P's user avatar
  • 4,128
-1 votes
1 answer
332 views

I am fairly new to golang and I am struggling to generate a one to many relationship map from existing map. Here is my script playground Explanation:- I am trying to achieve the relation of each ...
Bhargavi Pise's user avatar
0 votes
1 answer
6k views

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{} ...
Atif Ali's user avatar
  • 2,837
-2 votes
1 answer
978 views

I have a code that is not clean. I want to increment Counter in struct of NameLike but I think this is not effective. package main import "fmt" type NameLike struct { Name string ...
Rizal Arfiyan's user avatar
3 votes
1 answer
2k views

I am trying to implement http request limiter to allow 10 request per second per user by their usernames. At the max 10 request can be hit to the server including requests which are under processing. ...
ganesh.go's user avatar
-2 votes
3 answers
2k views

I ran into this simple Golang code and was surprised by Go's behavior here. Can someone explain what is going on here, and how to write the below code correctly? As you can see, I have a map, where ...
lajosdeme's user avatar
  • 2,447
6 votes
3 answers
4k views

This question is already answered in many other languages. In golang with simple maps (no nesting) how to find out if a map is subset of another. for example: map[string]string{"a": "b&...
Xaqron's user avatar
  • 31k
1 vote
1 answer
422 views

I have a struct, MyStruct, which contains a map. I want to make the access to the map safe for concurrent read and write but I also want to stick to the base Map and not use sync.Map. For this reason ...
Picci's user avatar
  • 17.8k
1 vote
0 answers
84 views

Are there any programming pitfalls of using maps in this manner: type Set struct { theMap map[interface{}]struct{} } StringSet := NewSet("abc", "pqr") IntSet := NewSet(1, 2) ...
user avatar
-2 votes
1 answer
869 views

I will be receiving strings one by one from a framework, I need to hold them in some container and delete some of them later. Now I have 2 options :- Create a slice of strings and then delete some ...
Anand Shah's user avatar
1 vote
1 answer
624 views

I have a map that uses an interface as the key. The map is defined like this MyMap map[Signature]Packets. The interface is Signature, and there will be two structs A and B that implement this ...
Sebastian's user avatar
0 votes
1 answer
61 views

I am trying to create a response like this: "GameController" => [ "methods" => [ "get", "post", "put", "...
Anish B's user avatar
  • 23
0 votes
0 answers
575 views

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 ...
Maxwell's user avatar
  • 105
-3 votes
1 answer
116 views

I came across this piece of code and was wondering if this needs to have a R/W Mutex. method(){ var ( wg sync.WaitGroup rwm sync.RWMutex vcnRegionMap map[string][]core....
f-z-N's user avatar
  • 1,837
-1 votes
2 answers
2k views

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 '=' ...
kokoko's user avatar
  • 4,128
0 votes
3 answers
5k views

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 ...
Sudheej's user avatar
  • 2,032
-1 votes
1 answer
759 views

I want to use a map's keys to request something from an API and then update the corresponding values based on the API's response. My guess would be the following code. Or maybe scratch this approach, ...
Rico's user avatar
  • 21
1 vote
1 answer
3k views

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 ...
Charas's user avatar
  • 1,837
-2 votes
2 answers
1k views

I have taken a variable like var u = make(map[string]interface{}) which means that a key could hold a string/int or another map. When I do the following it gives error cannot use v (type interface {})...
Volatil3's user avatar
  • 15.1k
0 votes
1 answer
648 views

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 ...
Michael Shum's user avatar
  • 2,647
-3 votes
1 answer
618 views

I am trying to append items to this struct I have: type AuditSource struct { Source map[string][]Pgm `json:"Source"` } type Pgm struct { ID uint `json:"id,omitempty"` ...
lakeIn231's user avatar
  • 1,311
3 votes
1 answer
2k views

I'm trying to call Go from c++. My code operates on maps, and I can't seem to make maps work with cgo. main.go: package main import ( "C" "fmt" ) func main() {} //export PrintMap func ...
speller's user avatar
  • 1,761
1 vote
3 answers
3k views

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 ...
Rahul Chawla's user avatar
0 votes
1 answer
200 views

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 ...
GeekyBoy's user avatar
2 votes
1 answer
1k views

Go maps are references to internal data. Meaning that when a map is "copied", they end up sharing the same reference and thus editing the same data. This is something highly different than having ...
Aurélien  Lambert's user avatar
0 votes
1 answer
411 views

I have data like following { "cars": { "toyota": [ "sedan", "pickup" ], "honda": [ "sedan", "couple", "pickup" ...
wzcwts521's user avatar
-1 votes
2 answers
780 views

When the formal parameter is map, assigning a value directly to a formal parameter cannot change the actual argument, but if you add a new key and value to the formal parameter, the actual argument ...
Wongfy's user avatar
  • 67
0 votes
1 answer
2k views

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 ...
Alexander's user avatar
  • 533