gluamapper icon indicating copy to clipboard operation
gluamapper copied to clipboard

Add support for metadata in gluamapper.Option struct

Open dnaeon opened this issue 9 years ago • 3 comments

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.

dnaeon avatar Jun 18 '16 21:06 dnaeon

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?

yuin avatar Jun 22 '16 15:06 yuin

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

dnaeon avatar Jun 22 '16 20:06 dnaeon

I would appreciate it if you could update the PR.

yuin avatar Jun 22 '16 23:06 yuin