mapstructure
mapstructure copied to clipboard
unsupported type for squash: interface
I would like to be able to build the target struct that decode maps into across different contributing pieces that are only stitched together at runtime. My approach for doing this is something like this where Bar extends a config stack by adding a Bar element around the wrapped config contained within:
type Wrapped interface{}
func (c *Bar) Stack(in interface{}) interface{} {
out = struct {
Wrapped `mapstructure:",squash"`
Bar string
}{
Wrapped: in,
}
return out
}
I'm using an anonymous interface as there is no anonymous struct. Unfortunately, mapstructure cannot decode squashed interfaces containing structs:
* Wrapped: unsupported type for squash: interface
Source code is there:
https://github.com/mitchellh/mapstructure/blob/5cc946fb764668e1e11b28b4fee49969c64aa8f6/mapstructure.go#L1221
Is that something that could be changed? Would be happy to look into a PR here.
Yes this should be fixable, if you want to take a stab at it I'd appreciate it.
@andig @mitchellh Created PR to add this functionality: #325