Last active
October 1, 2018 20:14
-
-
Save davars/c30a887a34b3072a47dd92a6e565b58c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import( | |
"github.com/mitchellh/mapstructure" | |
) | |
type A struct { | |
One string | |
internalA string | |
} | |
func (a *A) Metadata() map[string]string { | |
return map[string]string{"a": a.internalA} | |
} | |
type B struct { | |
One *string | |
Meta map[string]string `mapstructure:"metadata"` | |
} | |
func main() { | |
a := A{One: "foo", internalA: "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