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

merge two struct not expected performance #308

Open
semi-xi opened this issue Aug 15, 2024 · 1 comment
Open

merge two struct not expected performance #308

semi-xi opened this issue Aug 15, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@semi-xi
Copy link

semi-xi commented Aug 15, 2024

Describe the bug
i have two struct, when i load them, i wish the same key will be merge,but not. i read the source code,it seems already merge not return
image

To Reproduce

type A struct {
	A string
	B string
	C string
	D string
}
k := koanf.New(".")

	a := &A{
		A: "1",
		B: "2",
		C: "3",
		D: "4",
	}

	b := &A{
		A: "5",
		D: "8",
	}

	if err := k.Load(structs.Provider(a, ""), nil); err != nil {
                 fmt.Printf("load baseRootCfg fail:", err)
		panic(err)
	}

	if err := k.Load(structs.Provider(b, ""), nil); err != nil {
		fmt.Printf("load config.Dubbo fail:", err)
		panic(err)
	}

i try useMerge, but is the same result

k2 := koanf.New(".")
if err := k2.Load(structs.Provider(b, ""), nil); err != nil {
    logger.Error("load config.Dubbo fail:", err)
    panic(err)
}

if err := k.Merge(k2); err != nil {
    logger.Error("error merging k2: %v", err)
}

Expected behavior
Merge the two structures normally, if the same key, use the finally value

Please provide the following information):

  • OS: [osx]
  • Koanf Version [1.5.0]
@semi-xi semi-xi added the bug Something isn't working label Aug 15, 2024
@knadh
Copy link
Owner

knadh commented Aug 16, 2024

Please see #299

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants