Custom Map function
tehsphinx opened this issue · comments
Similar to the json.Marshal()
it would be really great to have the ability to add my own Map()
function to a struct in order to overwrite the default mapping.
Example use case:
type foo struct {
data bar
}
type bar struct {
Name string
Value string
}
func main() {
f := &foo{
data: bar{
Name: "foo",
Value: "bar",
},
}
fmt.Println(structs.Map(f))
}
In this example the actual data is hidden away and only accessible from the foo struct itself (at least outside the package). So I would want to build a function foo.Map()
that can extract the data. In a nested case it is necessary that the map package calls the custom Map
function if it exists.
see #101