Skip to content

MapTo() doesn't seem to handle embedded struct #241

Description

@tevino

Describe the bug
MapTo() doesn't seem to handle embedded struct

To Reproduce

const INI = `
[Section]
FieldInSubSection = 1
FieldInSection = 2
`

type File struct {
	Section `ini:"Section"`
}

type Section struct {
	SubSection
	FieldInSection string `ini:"FieldInSection"`
}
type SubSection struct {
	FieldInSubSection string `ini:"FieldInSubSection"`
}

func main() {
	iniFile, err := ini.Load(strings.NewReader(INI))
	if err != nil {
		log.Fatalf("load error: %v", err)
	}
	f := new(File)
	iniFile.MapTo(f)
	fmt.Printf("%+v", f)  // FieldInSubSection is not mapped
}

https://play.golang.org/p/cymqihBewXM

Expected behavior
f.FieldInSubSection == "1"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions