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

In some cases, copying all variables failed when using tags to copy #197

Open
xichencx opened this issue Oct 17, 2023 · 3 comments
Open
Assignees

Comments

@xichencx
Copy link

Reproducible Example

func TestName(t *testing.T) {
t.Run("validate error flag name", func(t *testing.T) {
type SrcTags struct {
field1 string
Field2 string
}

	type DestTags struct {
		Field1 string `copier:"field1"`
		Field2 string `copier:"Field2"`
	}

	dst := &DestTags{}
	src := &SrcTags{
		field1: "Field1->Field1",
		Field2: "Field2->Field2",
	}
	err := copier.Copy(dst, src)

	t.Log(dst)
	if err == nil {
		t.Fatal("must validate error")
	}
})

}

Description

src structure中存在私有变量,dst structure中使用copier标签进行拷贝会导致src structure中其他变量拷贝失败

@XiXiangFiles
Copy link

I don't believe this is a bug. The private field I expect should not be copied, and an error should be returned. What are your expectations regarding this?

@xichencx
Copy link
Author

xichencx commented Nov 21, 2023

I don't believe this is a bug. The private field I expect should not be copied, and an error should be returned. What are your expectations regarding this?

如果按照上述说法,那我这种方式去进行copy的时候会成功

`func TestName(t *testing.T) {
t.Run("validate error flag name", func(t *testing.T) {
type SrcTags struct {
Field1 string
field2 string
}

	type DestTags struct {
		Field1 string `copier:"Field1"`
		Field2 string `copier:"Field2"`
	}

	dst := &DestTags{}
	src := &SrcTags{
		Field1: "Field1->Field1",
		field2: "Field2->Field2",
	}
	err := copier.Copy(dst, src)

	t.Log(dst)
	if err == nil {
		t.Fatal("must validate error")
	}
})

}`
image

@XiXiangFiles
Copy link

@xichencx
here I tried your codebase. it'll raise an error, is it in your expectation? here
image

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

No branches or pull requests

3 participants