Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: control merging behavior #66

Merged
merged 3 commits into from
Apr 10, 2021
Merged

feature: control merging behavior #66

merged 3 commits into from
Apr 10, 2021

Conversation

grount
Copy link
Contributor

@grount grount commented Feb 23, 2021

issue #62

@knadh
Copy link
Owner

knadh commented Feb 23, 2021

Looks like there are merge conflicts on this after the #64 merge.

@grount
Copy link
Contributor Author

grount commented Feb 23, 2021

Should be good now.
Let me know if you think there should more changes to the docs.

@knadh
Copy link
Owner

knadh commented Mar 9, 2021

Hi @grount,
Would you be able to look at the comments I left?

@grount
Copy link
Contributor Author

grount commented Mar 9, 2021

@knadh what comments?

@knadh
Copy link
Owner

knadh commented Mar 9, 2021

Ah, are you unable to see the inline comments I added to the PR? https://github.com/knadh/koanf/pull/66/files

image

@grount
Copy link
Contributor Author

grount commented Mar 10, 2021

As you can see they are pending, you need to submit your comments in the top right (I think).

@knadh
Copy link
Owner

knadh commented Mar 10, 2021

What I meant was, would you be able to make the fixes posted in the inline comments so that we can merge this PR?

koanf.go Outdated
@@ -55,10 +69,23 @@ type UnmarshalConf struct {
// or a / for `parent/child/key`.
func New(delim string) *Koanf {
return &Koanf{
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can just return this:

return NewWithConf(Conf{Delim: delim})

maps.IntfaceKeysToStrings(c)
maps.Merge(c, ko.confMap)
if ko.conf.StrictMerge {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

err check can be in-lined.

maps/maps.go Outdated
@@ -132,6 +145,51 @@ func Merge(a, b map[string]interface{}) {
}
}

func MergeStrict(a, b map[string]interface{}) error {
mergeError := MergeStrictError{Errors: []error{}}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if skipping failures and collecting all errors is beneficial. We can just keep this idiomatic and return on the first error. That'll also combine MergeStrict() and mergeStrict().

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assuming I have 10 errors, that would require 10 runs to figure out all the errors.
That way he can fix all the possible errors.
WDYT?

Copy link
Owner

@knadh knadh Mar 23, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That could be said of any function that does multiple things, but collecting errors like that is an uncommon pattern. For instance, a JSON payload passed to json.Unmarshal() could have an indefinite number of errors, but the execution halts at the first error which is then immediately returned. We should keep this simple and return at the first error.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

// Does the key exist in the target map?
// If no, add it and move on.
bVal, ok := b[key]
if !ok {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we keep mergeStrict() exactly like merge() except for the additional type check that'll be added here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still need the fullKey to return the error message with the path to the key, otherwise it would be misleading.

@@ -132,6 +145,51 @@ func Merge(a, b map[string]interface{}) {
}
}

func MergeStrict(a, b map[string]interface{}) error {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing comment.

@knadh
Copy link
Owner

knadh commented Mar 10, 2021

@grount apologies. I added these comments weeks ago but missed hitting "Submit" to make them visible. Confusing GitHub UX.

Signed-off-by: Daniel Gront <grount1@gmail.com>
@grount
Copy link
Contributor Author

grount commented Apr 9, 2021

@knadh ping

@knadh knadh merged commit d4c432d into knadh:master Apr 10, 2021
@grount grount deleted the issue-62 branch April 18, 2021 07:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants