gookit / config

📝 Go configuration manage(load,get,set,export). support JSON, YAML, TOML, Properties, INI, HCL, ENV and Flags. Multi file load, data override merge, parse ENV var. Go应用配置加载管理,支持多种格式,多文件加载,远程文件加载,支持数据合并,解析环境变量名

Home Page:https://pkg.go.dev/github.com/gookit/config/v2

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

``Config.Set()`` is Not Override New Value if Value is Not The Same Type

KiddoV opened this issue · comments

The config.Set() should override the value even though the old value is not the same type of the new one.
EX:

{
  "parent": {
    "child": "Test Var"  
  }
}

After config.Set("parent.child.grandChild", "New Val") the object should be:

{
  "parent": {
    "child": {
      "grandChild": "New Val"  
    } 
  }
}

As for now, it does not change anything or not even throw any error. I think it is because parent.child value was a string so it doesn't allow me to add a new struct ({grandChild: "New Val"}) to it.

Any idea how to fix it?

I enhanced the Set logic:

Allow you change set parent.child value to {grandChild: "New Val"}.

But, Set("parent.child.grandChild", "New Val") is not allowed.

Better than nothing! Thanks!