Skip to content

How to take an existing Struct and turn it into a Map? #79

Description

@veqryn

This project says in its description: "Go library for decoding generic map values into native Go structures and vice versa."

However, I can't seem to figure out how to do the vice versa part.

Given the following:

type Person struct {
	Name   string
	Age    int
}

p := Person{
	Name: "Foo",
	Age: 30,
}

What function should I call to get this as a result:

m := mapstructure.Encode(p)

fmt.Printf("%#v", m)
// map[string]interface {}{"Age":30, "Name":"Foo"}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions