Skip to content

Instantly share code, notes, and snippets.

@mitchellh
Last active November 18, 2018 13:51
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mitchellh/6c57260ba2722ac7c28fe220ca4fb758 to your computer and use it in GitHub Desktop.
Save mitchellh/6c57260ba2722ac7c28fe220ca4fb758 to your computer and use it in GitHub Desktop.
import(
"github.com/mitchellh/mapstructure"
)
type A struct {
One string
Metadata map[string]string
}
type B struct {
One *string
Meta map[string]string `mapstructure:"metadata"`
}
func main() {
a := A{One: "foo", Metadata: map[string]string{"a": "b"}}
var b B
if err := mapstructure.Decode(a, &b); err != nil {
panic(err)
}
// b = B{One: &"foo", Meta: map[string]string{"a": "b"}}
// (Note: ^ I know the above is not valid Go syntax, but it gets
// the point across)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment