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
Describe the bug
When using MapToWithMapper() non-existing values are deleted, the expected behavior would be to leave those values intact, like advertised in the MapTo() documentation.
To Reproduce
The following code should add any values from defaultCfg that don't exist in the config file to said file, instead it adds all non-existing values as empty.
I submitted PR #422 to preserve defaults in preinitialized embedded pointers when MapToWithMapper maps an INI file, while still applying keys present in the file. I missed the contribution guide's requirement to comment here before starting.
Fixed in v2. MapTo now keeps an embedded struct pointer that is already set, so values the file doesn't have stay as they were. v1 replaced the pointer with a new zero struct.
cfg:=&MyIni{Blah: "value", SectionStruct: &SectionStruct{Meh: "value"}}
err:=ini.MapTo(cfg, configFilePath, ini.NameMapping(ini.TitleUnderscore)) // replaces MapToWithMapper// cfg.Meh is still "value" when the file doesn't set it
Fixed in unknwon.dev/ini/v2, v2.0.0-beta.1 and later. See the migration guide to move from v1.
Activity
[-]MapToWithMapper deletes non-existing values[/-][+]MapToWithMapper deletes default values[/+]normen commentedon Nov 24, 2020
As an update, this does NOT happen when the single sections of the file are MapTo'd
arojoal commentedon Sep 7, 2021
+1
Narek-Khachikyan commentedon Nov 8, 2026
I submitted PR #422 to preserve defaults in preinitialized embedded pointers when
MapToWithMappermaps an INI file, while still applying keys present in the file. I missed the contribution guide's requirement to comment here before starting.unknwon commentedon Nov 11, 2026
Fixed in v2.
MapTonow keeps an embedded struct pointer that is already set, so values the file doesn't have stay as they were. v1 replaced the pointer with a new zero struct.Fixed in
unknwon.dev/ini/v2, v2.0.0-beta.1 and later. See the migration guide to move from v1.