Open gheinrich-dd opened 1 month ago
Hi @gheinrich-dd. Apologies for the delayed reply. fatih/structs
is frozen, so there is no possibility of getting a fix in. Perhaps a solution here is to use JSON marshalling to get a map[string]interface{}
and to merge that into koanf directly without using the structs package. In fact, the structs provider could do this internally and get rid of fatih/structs
.
Describe the bug Hi, recently started using your package and enjoy using it. I did unfortunately come across what seems to be a bug in
fatih/structs
, which ultimately ends up breaking some merge behavior forstructs.Provider()
. The tl;dr of the bug is that if you have a struct where all fields are default values,fatih/structs
will think there was a problem representing the struct as a raw map and will leave the value in tact as the original struct value rather than turning it intomap[string]any
. The code that causes this can be found here.To Reproduce
Expected behavior In the code above, the expected behavior is that the overrides don't change anything. The
street
value in theAddress
struct is empty, and so it should get dropped out because ofomitempty
, effectively meaning you're merging{ "address": { } }
into the existing value. Instead,fatih/structs
leaves theAddress
struct value intact rather than converting it tomap[string]any
and dropping out thestreet
field, causing thestreet
value to get trampled by the empty value.Please provide the following information):
Additional context In my company's codebase, I got around this issue by implementing a custom structs provider that does a json marshal and unmarshal into
map[string]any
.