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
Undefined reference to <variable/function> error in Golang
Contains, ContainsAny, Count and EqualFold string functions in Go Language
Struct Instantiation using new keyword
GO Hello World program
Golang program to implement Binary Tree
Go program to find Forward(A) record of a domain
How do you write multi-line strings in Go?
Illustration of Checkpoint Synchronization in Golang
How do you send an HTTP PATCH request in Go?
Exploring Blockchain: Top 15 Real-World Use Cases in 2024