Skip to content

Add support for metadata in gluamapper.Option struct#3

Open
dnaeon wants to merge 1 commit intoyuin:masterfrom
dnaeon:mapstructure-metadata
Open

Add support for metadata in gluamapper.Option struct#3
dnaeon wants to merge 1 commit intoyuin:masterfrom
dnaeon:mapstructure-metadata

Conversation

@dnaeon
Copy link

@dnaeon dnaeon commented Jun 18, 2016

Adding support for metadata allows for inspecting the result of decoding and is useful in situations where we need to verify a list of required fields or unused ones.

A better approach would be to simply embed mapstructure.DecoderConfig in gluamapper.Option, but doing that would introduce a breaking API change, so with this commit I'm simply adding mapstructure.Metadata to gluamapper.Option struct for now. In future commits we should probably consider simply embedding DecoderConfig into Option struct.

@yuin
Copy link
Owner

yuin commented Jun 22, 2016

Thanks for you PR, and sorry for my late reply.(My job has gotten a little busy)

I think that it would be better to hide backend library APIs from gluermapper APIs.

Adding something like the following code to gluamapper.go

type Metadata struct {
    Keys []string
    Unused []string
}
    metadata := &mapstructure.Metadata{}
    metadata.Keys = opt.Metadata.Keys
    metadata.Unused = opt.Metadata.Unused 
    config := &mapstructure.DecoderConfig{
        WeaklyTypedInput: true,
        Result:           st,
        TagName:          opt.TagName,
        ErrorUnused:      opt.ErrorUnused,
        Metadata:         metadata,
    }

Are you in favor of this plan?

@dnaeon
Copy link
Author

dnaeon commented Jun 22, 2016

Sounds good. Do you want me to update the PR or you will do it instead?

@yuin
Copy link
Owner

yuin commented Jun 22, 2016

I would appreciate it if you could update the PR.

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.

2 participants