koanf icon indicating copy to clipboard operation
koanf copied to clipboard

merge two struct not expected performance

Open semi-xi opened this issue 6 months ago • 1 comments

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 avatar Aug 15 '24 07:08 semi-xi