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

Enable option to not unwrap from pointer #29

Open
alexkreidler opened this issue Dec 29, 2019 · 0 comments
Open

Enable option to not unwrap from pointer #29

alexkreidler opened this issue Dec 29, 2019 · 0 comments

Comments

@alexkreidler
Copy link

From the last lines of copystructure.go:

// wrapPtr is a helper that takes v and always make it *v. copystructure
// stores things internally as pointers until the last moment before unwrapping

Feature request: add an option (in Config) or somewhere to disable unwrapping at the last step.

This would allow an API like copystructure.Copy(val MyStruct) *MyStruct, which I believe would be useful for many people.

It would then make reflect.ValueOf(m *MyStruct).CanSet() true allowing me to use copystructure in conjunction with mapstructure. (e.g. I copy a struct and then decode a map into it)

My situation

My specific use case is I have a function GetConfig() interface{} which returns an interface{} containing some type of struct.

I want to decode a map into this struct using mapstructure, but I can't because the interface{} only contains a MyStruct{} not a *MyStruct{}, so CanSet is false. Additionally, mapstructure doesn't support decoding into a *interface{}, and even if it did, the underlying struct still wouldn't be able to be modified.

However I think if I can copy the interface{}/MyStruct{} to a *MyStruct I would be able to use mapstructure to do what I want.

I don't know enough about the internals to do this, but it seems like a simple thing if I just knew where.

I would really appreciate this, it would make all the difference!

Thanks for making some awesome libraries!

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

No branches or pull requests

1 participant