package main import ( "fmt" "github.com/mitchellh/mapstructure" ) type User struct { Name string Age int } func MapToStruct() { mapInstance := make(map[string]interface{}) mapInstance["name"] = "stefan" mapInstance["age"] = 28 fmt.Println(mapInstance) var person User if err := mapstructure.Decode(mapInstance, &person); err != nil { fmt.Println(err) } fmt.Printf("struct:%v", person) fmt.Println(person.Name,person.Age) } func main() { MapToStruct() }