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

Copy different field name from tag flag #86

Merged
merged 8 commits into from
May 31, 2021

Conversation

tomtwinkle
Copy link
Contributor

Specifying a name for the copier:"<Name>" tag, it is possible to copy the value to a field with a different field name.
To distinguish it from other flags, only the public field is supported.

	type SrcTags struct {
		FieldA string
		FieldB string `copier:"Field2"`
		FieldC string `copier:"FieldTagMatch"`
	}

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

	dst := &DestTags{}
	src := &SrcTags{
		FieldA: "FieldA->Field1",
		FieldB: "FieldB->Field2",
		FieldC: "FieldC->Field3",
	}
	copier.Copy(dst, src)

	fmt.Printf("%+v", dst)
	// &{Field1:FieldA->Field1 Field2:FieldB->Field2 Field3:FieldC->Field3}

@tomtwinkle tomtwinkle force-pushed the feature/field-name-tags branch from 729745c to fed2644 Compare March 19, 2021 02:17
@jinzhu jinzhu merged commit b63539f into jinzhu:master May 31, 2021
@jinzhu
Copy link
Owner

jinzhu commented May 31, 2021

thank you for your PR.

@tomtwinkle tomtwinkle deleted the feature/field-name-tags branch June 7, 2022 03:01
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.

5 participants