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

Emptying dst slice #83

Closed
trajber opened this issue Jun 9, 2018 · 1 comment
Closed

Emptying dst slice #83

trajber opened this issue Jun 9, 2018 · 1 comment
Labels

Comments

@trajber
Copy link

trajber commented Jun 9, 2018

is this behavior correct?
I was expecting the dst.Data to be empty after the merge since I'm using the Overwrite option.

package main

import (
	"fmt"

	"github.com/imdario/mergo"
)

type My struct {
	Data []int
}

func main() {
	dst := My{Data: []int{1, 2, 3}}
	new := My{}

	mergo.MergeWithOverwrite(&dst, new)
	fmt.Println(dst)
}
darccio added a commit that referenced this issue Jul 17, 2020
@darccio
Copy link
Owner

darccio commented Jul 17, 2020

This works:

	dst := My{Data: []int{1, 2, 3}}
	new := My{}
	if err := Merge(&dst, new, WithOverwriteWithEmptyValue); err != nil {
		t.Error(err)
	}
	if len(dst.Data) > 0 {
		t.Errorf("expected empty slice, got %v", dst.Data)
	}

@darccio darccio closed this as completed Jul 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants