Repository navigation
Conversation
MapTo, StrictMapTo and ReflectFrom read the ini tag. StructTag("json")
makes them read json tags instead, with the same syntax (#376).
This branch has not been deployed
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Describe the pull request
Adds a
StructTag(name)load option soMapTo,StrictMapToandReflectFromread field names from another struct tag, such asjson, instead ofini. This lets one struct carry a single set of tags for several formats.The chosen tag keeps the
initag's syntax:-skips the field, andomitempty,allowshadow,nonuniqueandextendsafter the name apply. Other options, such as json'sstring, are ignored. Thedelimandcommenttags are unchanged. It's a load option, likeNameMapping, because struct mapping reads its settings from theFile. The default staysini, so nothing changes for existing code.Link to the issue: closes #376
Checklist
AI usage
Written by Amp (an AI coding agent) at the maintainer's request. Validation:
go test ./...andgo vet.TestStructTagmaps and reflects a nested struct whosejsonandinitags differ, with-andomitempty. It fails when the option is ignored.