You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.
// 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!
The text was updated successfully, but these errors were encountered:
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
From the last lines of
copystructure.go
: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 usecopystructure
in conjunction withmapstructure
. (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 aMyStruct{}
not a*MyStruct{}
, soCanSet
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 usemapstructure
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!
The text was updated successfully, but these errors were encountered: