Skip to content

Reflect From Struct - section name configuration for root level properties #325

Open

Description

@rpieczon

Describe the feature

Let me configure dedicated section for each structure's root level property.
Currently all root level properties goes into 'DEFAULT' section.

Describe the solution you'd like

type SampleStruct struct {
  Property1      string `ini:"section1#prop1"`
  Property2      string `ini:"section2#prop2"`
}
input := SampleStruct{
  Property1: "value1",
  Property2: "value2",
}

file := ini.Empty()
ini.ReflectFrom(file, &input)
cfg.WriteTo(os.Stdout)

Would generate:

[section1]
prop1: value1

[section2]
prop2: value2

Describe alternatives you've considered

type SampleStruct struct {
  Property1      string `ini:"prop1" section:"section1"`
  Property2      string `ini:"prop2" section:"section2"`
}

Additional context

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct

Activity

  1. added
    feature
    on Jun 6, 2022
  2. unknwon commented on Jun 25, 2022

    @unknwon
    Member

    Hey, if you just want to change the section for the entire struct, you can do:

    file := ini.Empty()
    -ini.ReflectFrom(file, &input)
    +file.Section("section1").ReflectFrom(&input)
  3. unknwon commented on Aug 11, 2022

    @unknwon
    Member

    @unknwon somehow section mapping via tags, as described by @rpieczon isn't working anymore.
    Could you please give an advice what I'm missing.

    This issue is a feature request, which means what's been descried is something missing :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions