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 Make an HTTP Server in Golang?
Implementing Multiple Interfaces in Go Programming Language
Contains, ContainsAny, Count and EqualFold string functions in Go Language
This sample program demonstrates how to create multiple goroutines and how the goroutine scheduler behaves with three logical processors.
Golang program for implementation of Huffman Coding Algorithm
How to get first and last element of slice in Golang?