darccio / mergo

Mergo: merging Go structs and maps since 2013

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Merge without override assume false is a valid non empty type

kotyara85 opened this issue · comments

Here's an example

type Option struct {
	test    bool
}

o := Option{}

mergo.Merge(&o, &Option{test: true})

In this example test will be false. WithOverride won't really work here, because any other type will be overwritten in this case.
I guess custom transformers will help here?

Thanks for opening a new issue. The team has been notified and will review it as soon as possible.
For urgent issues and priority support, visit https://xscode.com/imdario/mergo

According to docs this is expected behavior
Mergo won't merge unexported (private) fields
Rename field test to Test and it will work as expected

I don't think this problem is just unexported variables. I think any false is considered empty and thus doesn't have the expected behavior.

@rfay I confirm it's just unexported variables, as @nilsgstrabo pointed. If you test it exporting test, it works as expected (no false value overrides a true value).