9951 explained code solutions for 126 technologies

golangHow to convert map to struct

package main

type person struct {
  name string
  position string

func main() {
  mp := make(map[string]string)

  mp["name"] = "Joe"
  mp["position"] = "president"
  p := person{name: mp["name"], position: mp["position"]}
}ctrl + c
package main

default package declaration


initialize map with string keys and string values

type person struct {

define sample struct to copy map values to

p := person{

create object of person struct type