type Foo struct {
A *string
B *string
C *string
D *string
}
m := map[string]string{"a": "a_value", "b": "b_value", "c": "c_value", "d": "d_value"}
a, b, c, d := m["a"], m["b"], m["c"], m["d"]
foo := Foo{
A: &a,
B: &b,
C: &c,
D: &d,
}
Is there a way to directly copy the map values into the struct, without using the intermediate local variables a
, b
, c
, d
?
Obviously I can't just write
foo := Foo{
A: &m["a"],
B: &m["b"],
C: &m["c"],
D: &m["d"],
}
because then Go thinks I want to take the address of the (not addressable) value while it is still in the map.