I would have expected this code to work:
package main
type Item struct {
Key string
Value string
}
type Blah struct {
Values []Item
}
func main() {
var list = [...]Item {
Item {
Key : "Hello1",
Value : "World1",
},
Item {
Key : "Hello1",
Value : "World1",
},
}
_ = Blah {
Values : &list,
}
}
I thought this would be the correct way of doing this; Values is a slice, list is an array. &list should be a slice, which is assignable to Item[], right?
...but instead, it errors with the message:
cannot use &list (type *[2]Item) as type []Item in assignment
In C, you'd write:
struct Item {
char *key;
char *value;
};
struct Blah {
struct Item *values;
};
How do you do that in Go?
I saw this question: Using a pointer to array
...but either the answers are for a previous version of Go, or they're just plain wrong. :/