Giter Site home page Giter Site logo

Comments (6)

knadh avatar knadh commented on May 18, 2024

Yep, the current behaviour is to overwrite the previous values in subsequent merges. To add type checks and other similar features, roughly:

  • Add a NewWithConf(delim, koanf.Conf{}) that takes a new koanf.Conf{} that can contain arbitrary feature flags.
  • koanf.Config { bool StrictMerge }
  • Make merge() behave differently based on this config value.
  • Will probably need a MergeStrict() in the maps package as well.

from koanf.

grount avatar grount commented on May 18, 2024

Thank you for the quick response!
Should I merge the delim field in the new koanf.Config?

from koanf.

knadh avatar knadh commented on May 18, 2024

Ah yes, makes sense.

from koanf.

grount avatar grount commented on May 18, 2024

maps.MergeStrict has to return an error since the merging process can fail.
In koanf, merge is used in 4 places:

  1. Load - can return an error.
  2. Cut - cannot return an error - but okay since it's a subset.
  3. Merge - cannot return an error - possible mergeStrict errors.
  4. MergeAt - cannot return an error - possible mergeStrict errors.

As I see it since the koanf.Conf has MergeStrict: true it should affect all the merging behavior across koanf.

Possible solutions:

  1. We can either exclude koanf.Merge and koanf.MergeAt by adding koanf.MergeStrict and koanf.MergeStrictAt and ignore the koanf.Conf
  2. We can ignore MergeStrict flag in koanf.Merge and koanf.MergeAt functions
  3. Change koanf.Merge and koanf.MergeAt signatures so it will return an error. I think it will not break backward compatibility.

I'm up for number 3, WDYT?

from koanf.

knadh avatar knadh commented on May 18, 2024

3 is the cleanest approach. We can bump the version to 1.0.0 after this. Long overdue.

from koanf.

grount avatar grount commented on May 18, 2024

Merging between JSON and YAML will fail because of the float64/int issue.
We can either say that you cannot MergeStrict between YAML and JSON and the recommended way is to use mergeStrict between the same types, or we can check if float64 is a whole number and convert to int but it will not cover cases where user-defined a whole float number: 3.0 but we can only patch one case where in the future there could be more of them.

from koanf.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.