Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

unsupported type for squash: interface #186

Open
andig opened this issue Apr 30, 2020 · 2 comments · May be fixed by #325
Open

unsupported type for squash: interface #186

andig opened this issue Apr 30, 2020 · 2 comments · May be fixed by #325

Comments

@andig
Copy link

andig commented Apr 30, 2020

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:

fmt.Errorf("%s: unsupported type for squash: %s", fieldType.Name, fieldKind))

Is that something that could be changed? Would be happy to look into a PR here.

@mitchellh
Copy link
Owner

Yes this should be fixable, if you want to take a stab at it I'd appreciate it.

@m1k1o
Copy link

m1k1o commented Apr 14, 2023

@andig @mitchellh Created PR to add this functionality: #325

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants