About 52 results
Open links in new tab
  1. go - Cannot assign to struct field in a map - Stack Overflow

    For anyone else who wants to understand this more, this seems to be a discussion of Addressability - though it seems to mostly focus on pointers, and doesn't explain why this …

  2. go - cannot assign to struct field in map - Stack Overflow

    May 8, 2018 · a.B is map as such you can not reference a field of it. If you want to access a field of an object in the map you will need to use a key like you do above a.B["two"].A.B = a.CB. If …

  3. Why do I get a "cannot assign" error when setting value to a struct …

    Sep 24, 2015 · The operand must be addressable, that is, either a variable, pointer indirection, or slice indexing operation; or a field selector of an addressable struct operand; or an array …

  4. Golang: I have a map of int to struct. Why can't I directly modify a ...

    Feb 26, 2020 · This is why when you modify it, the struct in the map remains unmutated until you overwrite it with the new copy. As RickyA pointed out in the comment, you can store the …

  5. cannot assign to struct field / assignment to entry in nil map

    Oct 2, 2018 · I've been racking my brain for about 4 hours now. I cannot make it work. In my opinion, I'm trying to do the same thing twice. I'm making a map of a field in a struct, and then …

  6. Accessing struct fields inside a map value (without copying)

    Dec 16, 2019 · Sure, the language creators would turn around and do a non-obvious thing of stating that while a "regular" map read, v = m[i], would copy the value out, the "modify field" …

  7. Cannot assign struct field in nested map Golang [duplicate]

    May 5, 2018 · type filesDB struct { Name string Content []byte } type fileDB struct { Files map[string]filesDB } Well, when I try to save data in JSON format with the maps, I try this: …

  8. go - Assign to anonymous struct value in map - Stack Overflow

    Apr 20, 2021 · Cannot assign to struct field in a map. 1. Add item to map inside of struct in Golang. 0.

  9. create map [string]struct {} and assign a value - Stack Overflow

    Aug 1, 2015 · The ContainerConfig is a struct. And there's a field Volumes, the type of which is type map[string] struct{}. I know that I could create such a map with make(map[string]struct{}) …

  10. Define and access map field inside struct in golang?

    Jun 11, 2018 · Suppose I have a struct named Test, type Test struct { Value1 int `json:"value1"` Value2 int `json:"Value2"` People map[string]string `json:"Value3"` Timeupdate string …