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