How to build a map of struct and append values to it?
Example
package main
import "fmt"
type Emp struct {
x int
y []string
}
func main() {
var list = map[string]*Emp{"e1": {1001, []string{"John", "US"}}}
e := new(Emp)
e.x = 1002
e.y = []string{"Rock", "UK"}
list["e2"] = e
fmt.Println(list["e1"])
fmt.Println(list["e2"])
}
&{1001 [John US]}
&{1002 [Rock UK]}
Most Helpful This Week
How to initialize a struct containing a slice of structs in Golang?
Golang panic recover example
How do you catch panic in Golang?
Concurrently printing array elements using goroutines and channels
How to append struct member dynamically using Empty Interface?
How to create Slice of Struct in Golang?